Add Swift Package in Xcode

Hi,

Overview

I would like to add a Swift Package to my Xcode project.

Problem

In Xcode when I select Project > Package Dependencies and Press + button to add a dependency it keeps spinning and doesn't end

Points to note:

  • This is a private GitHub repository
  • Uses SSH / tried with HTTPS as well
  • Xcode 26.5 (17F42)
  • macOS 26.5 (25F71)

I am able to clone the Swift Package URL on the command line.

Xcode has the GitHub account and I am able to push and pull code on that GitHub account, however searching SwiftPackage using the URL keeps spinning.

My failed attempt

  • rm -rf ~/Library/Developer/Xcode/DerivedData
  • rm -rf ~/Library/Caches/org.swift.swiftpm
  • plutil -remove IDESwiftPackageAdditionAssistantRecentlyUsedPackages ~/Library/Preferences/com.apple.dt.Xcode.plist
  • I have removed GitHub account in Xcode and added it again

I am confused if I am missing something very obvious, any help on this is much appreciated.

Questions

  1. Is there any workaround or way to fix this issue?
  2. Why does this take such a long time when I have a specific URL, either it needs to add it or return that the package is not found. Why is it searching?

You’re reporting an Xcode bug. You should either use Apple's Feedback app to report it, or start a thread on Apple's developer forum.

2 Likes

Thanks @snej

Sorry for causing noise, I have posted in the forum as well, just wasn't getting much traction.

I've found that, even when stuck spinning like that, putting a repo address in the search field can often get it to do the search and show proper results anyway, so you can try it. If you have a system proxy you can see what Xcode is trying to call and perhaps block it so it fails quickly rather than hanging.

2 Likes

Thank you so much @Jon_Shier

I had given it over 15 minutes, however may be I will let it continue to search. I will also see if there is a way to monitor / block the incorrect paths.

I had the same issue and it's probably not really helpful, but after trying all the things you have and more I only managed to fix it by factory resetting my mac. A bit extreme but I had work to do and after a week of troubleshooting and having to fall back to using one of our older macs I had had enough.

1 Like

@Aquaculture Thanks a lot

Just curious did you have SSH configured?

I think there are issues with SSH and SPM using Xcode.

I have only one git account added to Xcode.

It is surprising some face the issue while others don't.

I did have SSH configured and since I use about 20 packages, all from a personal repository I had to go and mirrors.json all of them since Xcode would keep saying that the SSH fingerprint was unknown. Even after clicking the error and trusting it.

Perhaps it loads infinitely because Xcodes built-in package manager tries to load all recent packages and then it gets stuck on the SSH ones?

Not sure what causes it. I never experienced infinite loading on my work at home mac, but my at work mac refused to load.

1 Like

For me there was no explicit error, it just kept spinning.

In fact I had cleared recent packages but that didn't help, so I don't think that is the issue (at least in my case).

Thanks a lot for your inputs, I will try to remove SSH and try using HTTPS.

Ah sorry I wasn't being very clear. I was getting an error when trying to update packages in existing projects with SSH dependencies on my private repo.

Ah ok, my issue is a bit different, I am not even able to add a Swift package (keep progress bar spinner keeps spinning).

I tried deleting SSH key locally and on the portal and restarting, yet doesn't work

It might be interesting to see (if possible) if you can update your package dependency via SSH in an existing project. I experienced both the infinite loading for adding a dependencty and the updating an existing dependency issue so they might be related to each other.

1 Like

Thanks @Aquaculture

I had a project with Swift Package A, I was able to edit that and change the URL to Swift Package B and now B gets pulled properly and I can see the files in B.

While editing an existing URL to a new URL there is no search screen, it is a simple edit. So the spinning issue doesn't exist during edit.

So the problem seems to be the UI which searches the package.

Is there a way around this to directly specify Swift Package URL without searching screen?

Note: I am now using HTTPS

@Aquaculture Thanks a ton!!! Your suggestion led me to the solution.

Problem

  • The actual issue for me is Xcode when adding a new package and entering the URL in the search box where it keeps spinning (even over an hour) never ends.

Workaround

  1. Add one of the Apple Swift Packages which comes pre-loaded with Xcode like swift-algorithms
  2. Once added that screen gets dismissed and the swift-algorithms URL is added as a dependency
  3. Now click on the swift-algorithms and change it to your URL and also update the Dependency Rule

This will add the your swift package and pull the code.

Side note: Realized I needed to add SSH key anyway to work with Xcode, so added that

Thank you so much @Aquaculture made my day! Was breaking my head over it.

That's great! Happy to hear that you managed to find a workaround. Happy coding :slight_smile:

1 Like