Xcode SPM when switching between branches

I have this problem with Xcode and SPM where every time I open up my Xcode project or switch branches, Xcode would spend a lot of time resolving the dependencies. I don't remember that that was a thing with Cocoapods.

Is there a way to prevent it from doing this? It slows down my machine and make it completely unusable for 5-15 mins so switch branches is always a pain.

EDIT: I would like to add that I have the Package.resolved file ignored under Git.

Post not yet marked as solved Up vote post of GiraffeCorps Down vote post of GiraffeCorps
4.2k views
  • As mentioned below, one workaround would be 1. close the project 2. use CLI or other tools to switch branch 3. open the project. In this way Xcode won't resolve the Swift packages again. But that doesn't help when someone uses Xcode's built-in Git client. Hope Xcode can add an option to allow manually resolve the packages when needed, just like the recent additions of "Clear All Issues" and "Clean Test Results".

Add a Comment

Replies

I have the same issue. When I open my project in Xcode or switch Git branch, Xcode starts to resolve package dependencies even if Package.resolved file has not changed. When package resolving ends it starts to indexing project. It all takes about a minute or two and CPU usage is about 500%. So, when I switch branch I can't use Xcode because it freezing.

+1. Very annoying

Same issue, can't build or run or really do anything for up to 15 minutes, happens with every branch change, any time I need to run clean, and sometimes just randomly. Makes Xcode almost completely unusable. Come on Apple do better! I am losing hours of time everyday to this crap

I always try to close my projects before switching branches. Even if the SPM dependencies are the same in the two branches it downloads them again. If I close the project, then switch the branch, then reopen the project it doesn't download the dependencies again.

I have Package.resolved in git since they could be different in the different branches.

  • What if you want to use Xcode as your git client? :D (It's finally getting somewhat usable...)

Add a Comment

Has anyone figured out how to resolve this? I already have Package.resolved being ignored by git but every time I switch branches resolving dependencies starts all over again. A few things do get updated when I switch branches (like bundle id, app name etc) but I don't think that should trigger SPM dependency resolution again b/c the packages are exactly the same.

Thanks in advance.

This problem still persists. It is very disruptive in our day to day workflow. Has anyone found a solution to this?

  • Same issue.. wish there was at least an option to disable SPM temporarily so I could update branches and switch back without losing 30-40 mins

Add a Comment

Extremely annoying and unnecessary. If the Package.resolved file is unchanged there is simply no need for a new resolve... This bothers me multiple times every day. I can't believe it hasn't been fixed yet. SPM in Xcode seems to work very bad for being the future alternative endorsed by Apple.

I posted here about this issue about six months ago.. Just the other day though I added "-clonedSourcePackagesDirPath SourcePackages" to my xcodebuild command and so far I haven't experienced the problem – I won't know for sure if this is true true fix or not for a while because the issue was intermittent for me, but so far so good. The idea is to cache the SPM dependencies in the project dir instead of the default behavior which places them in derived data. I read about it – after trying, again, to find a solution – here: https://www.uptech.team/blog/swift-package-manager. Anyway I hope this works, otherwise I have to seriously consider going back to CocoaPods.

@sesingh Were you successful or did you end up moving back to Cocoapods?