Chapter 4. Swift Package Manager
Reinventing the wheel is a great way to waste your time and effort. When another developer has already created a solid library that performs a function needed by your application, you can save weeks of time if you are able to reuse it. The Swift ecosystem is growing very quickly, and often there are many similar libraries that solve the same problem. If you adopt Swift for your project, you will find hundreds of Swift packages on GitHub or listed in the IBM Swift Package Catalog, which can be easily incorporated with the aid of the Swift Package Manager (SwiftPM). Whether you are looking to store your data in a database, parse JSON, or use reactive programming, chances are that there is a Swift package out there that can do what you need it to.
As a developer, you might want to add one of these libraries to your project. This is where the SwiftPM comes into play. If you already use a package manager such as Rust’s Cargo, NodeJS’s npm, Java’s Maven, or Ruby’s Gem, you will feel right at home using the SwiftPM. It helps to resolve dependencies by automatically downloading the sources that match the version you want, and arranges the build process so that you have the executable or Swift library that you need. Because the SwiftPM works on many platforms, you can kick off builds, test, or fetch dependencies with shell commands. In addition, you can use it to generate an Xcode project, as described in “Developing in Xcode”.
Semantic Versioning
When ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access