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.

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.

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?

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.

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".

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

It's very frustrating that this has been a problem for so long.... I and everyone else on the iOS team at work has to run

git restore *.xcworkspace/xcshareddata/swiftpm/Package.resolved

every. single. time. we switch branches. Sometimes we accidentally commit the deletion of Package.resolved into git and it screws up our Xcode Cloud pipeline.

Any suggestions other than quitting & relaunching Xcode before & after switching branches? Has anyone had success with git hooks?


I switched to SPM to avoid versioning issues with cocoapods + xcode. Cocoapods is volunteer-driven and xcode can make any change they want, regardless of what cocoapods supports. I don't want that bringing my development to a screeching halt, so I choose SPM.

I miss the way that cocoapods works. My project is not a swift package. Why can't I define a Package.swift file (or something of the like) as the source of truth for the dependencies of my project, and just put Package.resolved in my .gitignore? Xcode could have the location of Package.swift as a setting in .pbxproj, and interpret when resolving dependencies. I get to decide when I want to update my package dependencies (xcodebuild spm install or xcodebuild spm update or something like that). Why not?? Am I missing something??

  1. Create a local SPM in your project

  1. Add all your dependency packages into the Package file

e.x.

import PackageDescription

let package = Package(
    name: "Dependencies",
    products: [
        .library(
            name: "Dependencies",
            targets: ["Dependencies"]),
    ],
    dependencies: [
        .package(url: "https://package_url.git",
                 exact: "0.0.1"),
    ],
    targets: [
        .target(
            name: "Dependencies",
            dependencies: [
                .product(name: "package_name", package: "package_name"),
            ]
        ),
        .testTarget(
            name: "DependenciesTests",
            dependencies: ["Dependencies"]),
    ]
)
  1. Go to target -> General -> Frameworks, Libraries, and Embedded Content

add Dependencies

  1. close Xcode and apply this commit to all branches

  2. reopen Xcode

Xcode SPM when switching between branches
 
 
Q