sak
sak

Reputation: 3307

How to do top-of-tree development with Swift Package Manager and XCode?

So I am working on two packages in tandem, where Package A depends on Package B.

Package A -> Package B

Each package is in a separate git repository, and I would like to avoid having to push changes from Package B to remote every time I make a change just to be able to use it with Package A.

Using the documentation here, I have put Package B in edit mode like so:

$ cd /path/to/package_a/checkout/location
$ swift package edit PackageB --path /path/to/package_b/checkout/location

Based on my understanding, this should basically tell SPM to reference the local checkout of the package, at the specified --path, rather than managing its own checkout.

But the thing is, if I open package A in XCode:

open /path/to/package_a/checkout/location/Package.swift

And I go to "show source" on Package B, it's showing me the checkout in the derived data folder.

So it seems like XCode is not observing the edit mode configuration provided by SPM? Or else how do I achieve having XCode point to a local checkout of a package rather than the default behavior?

Upvotes: 2

Views: 162

Answers (1)

Michael McGuire
Michael McGuire

Reputation: 3910

You can use Xcode to work on a Swift Package (Package.swift) and also edit a dependency of that package, but it requires the creation of an empty xcworkspace rather than using the swift package edit command, which doesn't seem to be supported in Xcode. Full details in this blog post but the summary is:

  1. Create an empty workspace
  2. Draft the containing folder of the Swift Package you want to work on
  3. Wait for packages to resolve
  4. Drag the containing folder of the dependency you want to edit. The name of that folder needs to match the name of the dependency as it appeared after step 3. And make sure that it is a folder where you have the dependency checked out or is editable.
  5. Wait for packages to resolve
  6. Edit your current package and the dependency all together.

Step #4 is tricky because you need to make sure to drag it to the root of the workspace and not into the package you added in #2. Xcode makes this hard.

Upvotes: 0

Related Questions