84

After I create a new swift package with dependencies I call swift package generate-xcodeproj. If my dependencies have a new version I call swift package update. The new version of my dependency gets downloaded and built but Xcode now has a bad reference to the old version of the dependency. I can call swift package generate-xcodeproj again but this will remove any custom targets I have setup.

How do I update my swift dependencies and my Xcode project without deleting my custom targets?

2
  • 2
    I have this same question. Generating a new copy of the .xcodeproj also removes any folder structure that was being used to organize source files. Commented Feb 17, 2017 at 19:00
  • 2
    I built a tool to help with this. github.com/saltzmanjoelh/XcodeHelperCli After you build and copy it to /usr/local/bin or wherever you can call xchelper update-packages -s This will update your packages and create symlinks for your Xcode project. This way when your packages get new versions, you don't have to update the references manually. Commented Feb 18, 2017 at 3:45

7 Answers 7

98

I just stumbled upon this question and found that the solution to "How to update swift dependencies in Xcode" has probably changed now that Swift Packages have been around for a few years.

For me, the solutions was to simply go to File -> Swift Packages -> Update to Latest Package Versions.

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

Surprisingly, for me, Facebook 7.1.1 doesn't upgrade to 8.0. Is there anything else I need to do?
Transitive dependencies may be pinning the version @Zorayr.
In my case the menu File -> Packages is disabled (Xcode 13.4), anyone else having the same problem?
This is an incomplete advice for most users, that have a version rule in place (even without them knowing). The answer below provides a more detailed explanation.
88

Many of the problems with packages not updating are because the swift package version rules limit the automatic package updates to the current major version only, i.e v3.3.1 of a package will update to v3.4.0, but will not update automatically to v4.0.1. Therefore using the update options in Xcode does not necessarily get the latest major version of a package.

To resolve, Open the project from the project panel, select the project (not the targets), then select the "Swift Packages" tab. Double click on the package you want to update and change the minimum version to the next major version.

enter image description here

5 Comments

This is the answer for many. The package manager won't grab the next major without this intervention I believe.
this indeed is the answer. I still find it terrible UX that one manages the packages from totally disconnected places
For me, after doing this I also had to do File -> Packages -> Update to Latest Package Versions
Couldn't imagine that the section was hidden in such an obscure place. The screenshot helps a ton!
In Xcode 15 this is now called "Package Dependencies". Still the same convoluted, disjointed process...
25

- Update a single dependency using Xcode

This method will save a lot of resources and time. Because it won't force other packages to redownload.

Double click on the package in the tab you mentioned and change the version to anything else. It will then recheck the remote repo. The benefit of doing this is to only update the selected package. (Also, it's better to have the current using version be set in the package.)


- Update ALL dependencies using Xcode

From File -> Swift Packages -> Update to Latest Package Versions

SS


🤨 Single package with GUI (Xcode 12 and above)

Right-click on the package from the left navigation pan and select Update Package

Xcode 13

note that you will see Xcode saying update all packages but it will update only the selected one

1 Comment

The single package update is not available on XCode 12.2 unfortunately
16
+250

Instead of trying to preserve your changes to generated project, you can manage dependencies in a separate project, like CocoaPods does.

When starting new project:

  1. create Xcode project for your app MyApp.xcodeproj
  2. save as a workspace MyApp.xcworkspace
  3. create package for your dependencies
mkdir MyDeps && cd MyDeps
swift package init --type library
  1. add dependencies to Package.swift
  2. generate Xcode project for the dependencies package
swift package generate-xcodeproj
  1. add generated project MyDeps.xcodeproj to your workspace MyApp.xcworkspace
  2. add target MyDeps.framework to Linked Frameworks of your app MyApp.xcodeproj

With this setup you can freely update dependencies in Package.swift and regenerate dependent project as needed.

2 Comments

I haven't tried this, but wouldn't this require you to import all the dependencies at once? Like, you'll have to do import MyDeps, right? And then, all the dependencies are imported?
With later versions of Swift, this will give a warning: warning: Xcode can open and build Swift Packages directly. 'generate-xcodeproj' is no longer needed and will be deprecated soon. error: InternalError(description: "Internal error. Please file a bug at https://bugs.swift.org with this info. plugin not supported")
6

Maybe this will help someone.

Project Explorer -> root folder -> Project Name -> Package Dependencies -> Update desired package version

XCode screenshot

Comments

4

I had an issue with CryptoSwift using Xcode 12.5. My version was 1.3.1 and the issue was fixed in 1.4.0. I tried :

  1. updating by File -> Swift Packages -> Update to Latest Package Versions.
  2. xcodebuild -resolvePackageDependencies

But both did not work.

I manually went and changed target -> Swift packages -> Version rules and Xcode automatically installed the newer version and I was out of my error.

1 Comment

It looks like there's a different location in Xcode 13.4.1 > Project > Package Dependencies [Version Rules]
0

If the library is used by a particular target, the library won't be updated to the latest version, at least in my case (Xcode 14.2).

I was using OneSignal which requires to add a target (OneSignalNotificationServiceExtension) which depends on the OneSignal library in the "Frameworks and libraries".

So:

  1. remove the required lib voice from the dependency in the extension,
  2. update the library with right click -> "update package"
  3. re-add to the extension the updated library in the "Frameworks and libraries"

Screenshot of which row to delete to let the library update properly (remember to read later).

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.