How to use Swift Package Manager in your iOS project
- May 27, 2020
- John Codeos
In this tutorial, I’m going to show you how to add Swift Package Manager in your iOS project.
Swift Package Manager (SPM) is a tool that lets you install dependencies in your project, like Cocoapods and Carthage, but this is built-in in the Xcode, easy to manage and also supported by Apple.
In the downside, you have to install the dependencies one-by-one (There’s no other way as I type these words), and also many repos (3rd Party Libraries) don’t have SPM support.
Adding Package Dependencies
To install a dependency in your iOS project, go to File > Swift Package > Add Package Dependency…
In the new window, type the dependency’s name you want to download (e.g., Alamofire), or if you can’t find it, paste the repo URL and press Next
Next, select the Version (or Branch or Commit) you want to install, and press Next.
You can also select a specific version of the dependency, just change the Up to Next Major to Exact.
Some old dependencies (e.g., DTCoreText) might not have Swift Package Manager (SPM) support, and you’ll get the following error:
To fix that, ask the person who maintains the dependency to add SPM support, or use other methods, like Cocoapods and Carthage.
At the last window, press Finish
You can find the installed dependencies in your project name under PROJECT > Swift Packages
Deleting Package Dependencies
If you want to remove a dependency, go to your project name under PROJECT > Swift Packages, select the dependency you want to delete and press the – button
Next, on the pop up window, press Remove
If you have any questions, please feel free to leave a comment below