Editing a Package Dependency as a Local Package

Editing a Package Dependency as a Local Package

The reason you cannot see the content of the package is that you have it open in another Xcode instance.

You can only edit a package in one Xcode instance at a time.

I find closing down Xcode completely, then opening up the particular project that I want to edit the package in solves the problem.

How do I put a swift package in Edit Mode?

If you clone a package locally and drag it into your project or workspace, that local copy will override the (read-only) remote dependency anywhere it was referenced. You can then edit the local copy of the package as needed.

You can see more on this workflow about 23 minutes into the WWDC2019 video for Creating Swift Packages: https://developer.apple.com/videos/play/wwdc2019/410/

Editable Swift package in Xcode project?

I've discovered that I can do this, so I'm answering my own question.

You can use a "local package" as described in this short article from Apple: Developing a Swift Package in Tandem with an App

I keep the same configuration as before — my app project still has a Swift package dependency defined, and that dependency still points to the same URL for the git repo. But now I also checkout/clone a local copy of that repo, into my app's project directory, or maybe one level up if I'm using an Xcode workspace. Then I drag that cloned directory to the Xcode project navigator. As soon as you drop that folder there, Xcode makes some adjustments to its UI, to reflect that it's using it as a local version of the package. You can edit the files there, and push changes back to the main repo. If you delete that local clone, Xcode goes back to using the read-only version like before.

Adding Local dependencies in XCode11 using SPM

This is the way I did it :

  • Drag and drop your package folder (in my example "DataStructures") from the finder directly into the Frameworks group of your target. You will see that the dropped item take a brown folder color (you can use the arrow to "get into it").
  • Go to your project target page, in the "Framework and Libraries" click the "+" button. Your package should show up in the "Workspace" area as a library.

Sample Image

Local Swift Packages Stopped Working in Xcode 13

Removing package references from workspace and re-adding them (by simple drag-n-drop from Finder) resolved the problem.

I even didn't need to reconfigure corresponding schemes, or re-adding dependencies in targets.



Related Topics



Leave a reply



Submit