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?
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.
To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter its repository URL.
To check for updates manually, choose Swift Publisher 5 > Check for Updates… in the menu. To check for updates automatically, select the corresponding check box in the program Preferences (Cmd-,). If you purchased the app from the Mac App Store, update it through the Updates tab of the Mac App Store.
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
.
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.
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:
MyApp.xcodeproj
MyApp.xcworkspace
mkdir MyDeps && cd MyDeps
swift package init --type library
Package.swift
swift package generate-xcodeproj
MyDeps.xcodeproj
to your workspace MyApp.xcworkspace
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.
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.)
From File -> Swift Packages -> Update to Latest Package Versions
Right-click on the package from the left navigation pan and select Update Package
note that you will see Xcode saying update all packages but it will update only the selected one
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 :
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With