How to update Swift dependencies in Xcode
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
.
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:
- create Xcode project for your app
MyApp.xcodeproj
- save as a workspace
MyApp.xcworkspace
- create package for your dependencies
mkdir MyDeps && cd MyDepsswift package init --type library
- add dependencies to
Package.swift
- generate Xcode project for the dependencies package
swift package generate-xcodeproj
- add generated project
MyDeps.xcodeproj
to your workspaceMyApp.xcworkspace
- add target
MyDeps.framework
to Linked Frameworks of your appMyApp.xcodeproj
With this setup you can freely update dependencies in Package.swift and regenerate dependent project as needed.
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.