Adding a Swift Package in Xcode is an extremely easy process and you’ll explore that in this article.
Swift Package Manager (SPM) was introduced in 2017, and it was a way to integrate libraries within your iOS application.
Previously, the iOS platform was dominated by CocoaPods, developed by the community and a few dedicated Ruby experts. It was groundbreaking because once, there wasn’t a way to automatically add dependencies, which would involve manually adding source files and dealing with the linking manually within Xcode.
However, SPM is now the future of adding libraries to your project. This is because it’s fully integrated within Xcode and is lightning fast to link all the required files to your project.
Adding a Swift Package
Open your Xcode project, navigate the File tab within the macOS bar, and click on “Add Packages”.
In the Add New Package window, you can select from recently used or Apple Swift Packages. Alternatively, you can search for a package via the name or the URL to the Github page.
You can click on the Add Package button, and it will be added to your iOS project and linked automatically. At this point, nothing else is required 🎉
Removing a Swift Package
You might be wondering how it’s possible to remove a Swift Package; the process is as easy as adding.
You can click on the “-” button, and after confirming the prompt, your package will be removed from Xcode, and it’s that easy.
You might often receive a corrupt
Package.resolved file, and if you ever receive this error, you have likely changed Xcode versions whilst opening a project using SPM. Therefore, if you receive this warning, you should delete the
If you run this command in Terminal, it will delete your
Package.resolved file and reopening the project should fix the error.
rm SwiftlyRush\ Bank.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Of course, you should replace the project name with yours ;]!
You have explored the basics of Swift Package Manager within Xcode. It’s straightforward to add libraries to your iOS project, and you can access a great range of projects using the Swift Package Index website.
You should get familiar with this process, and it’s worth exploring the different ways to update your packages and create your local package.
I can’t wait to see you using SPM in your future projects.