3

Just upgraded to Xcode 13.1 and opened a SPM project by clicking the Package.swift file that has some dependencies. In the former versions I could simply edit one of these dependencies by dragging a local clone of the package into the Project Navigator. Xcode was then going to ignore the checked out dependency and let me edit the local one. Apple documents this here.

When trying this with Xcode 13.1, Xcode just copies the folder into the project folder, like it does with normal files/folders that are not SPM projects.

Did I find a bug or missed I something?

Thanks!

Update: I found out how to work around by creating a .xcodeproj file with swift package generate-xcodeproj. There I could drag in the package as always. This works but is not the way to go, as the xcodeproj generation is deprecated by apple.

Michael_mhr
  • 744
  • 1
  • 9
  • 27
  • I have experienced the same issue. The documented instructions you link to have worked for me in the past but no longer work when using Xcode 13.1. When I drag the folder in Xcode asks me if I want to create a workspace because that's the only way to merge the files in, which is not the intention. I've made sure to try dragging the folder from finder to different locations in the project navigator tree and I get two results: 1) if I drag to the project folder structure, I get the error you mentions, 2) if I drag to the package dependencies section, Xcode cancels/rejects the operation. – dcow Nov 19 '21 at 23:39
  • @dcow You should drag the folder inside your project (on the project navigator), if drag it outside (above) your project then it would ask you to create a workspace. Ensure the package is not opened on a different Xcode window, if so close that window, quit Xcode and retry – user1046037 Dec 16 '21 at 00:45

2 Answers2

1

It looks like there is now an Add Local... button at the bottom of the add package wizard. Selecting the package from your local filesystem yields the same result as the "drag from finder" instructions you've linked.

The wizard is accessible from:

  • File > Add Packages, or
  • Project.xcodeproj > Package Dependencies > +.
dcow
  • 7,765
  • 3
  • 45
  • 65
  • 2
    Thanks for the answer! I already tried this button before... By clicking you can select a folder from the filesystem and Xcode automatically creates a package-entry for use in Package.swift. It doesn't even do anything but copy that entry to clipboard. Looks like this .package(path: "../some-package"). Unfortunately that doesn't solve this problem... – Michael_mhr Nov 21 '21 at 00:09
  • 1
    This may work for an normal Xcode project with an .xcodeproj file. I haven't tried. but doesn't for an SPM project with just a Package.swift – Michael_mhr Nov 21 '21 at 00:23
  • Good point, you're right I haven't tried in a `Package.swift`-only project. – dcow Nov 21 '21 at 17:28
  • @Michael_mhr have you found any solution yet? – user1046037 Dec 14 '21 at 13:54
  • @user1046037 I'm still using the .xcodeproj workaround. works perfectly in my case – Michael_mhr Dec 15 '21 at 14:17
  • @Michael_mhr My problem was I had the swift package opened on a different Xcode window, the source files didn't show up in the project navigator. Now it is resolved, I had to close that Xcode window - https://stackoverflow.com/questions/70350100/editing-a-package-dependency-as-a-local-package – user1046037 Dec 16 '21 at 00:40
0

I was having this problem, too, but after seeing the first comment on the other answer, I tried this:

I used File->Add Packages->Add Local…->navigate to local clone of dependency->Copy Package, which indeed seems to do nothing, but it puts a .package dependency line onto the clipboard.

I then edited my main project’s Package.swift to replace the existing Github dependency with the contents of the clipboard. Now I can edit the dependency’s files directly in the “Package Dependencies” portion of the project contents pane (which I wish you could do for a regular Xcode project too).

This solution kinda sucks, because it forces me to modify Package.swift, which means everyone on the team has to set things up the same way. Fortunately, I'm the only one working on this project, but future me is sure to be bitten by this.

Rick
  • 3,298
  • 3
  • 29
  • 47