Swift Package Manager in Xcode 12.0
Adding SPM dependency to an existing project
Input Repository URL Link that has SPM support
Note: Visit https://swiftpackageindex.com and search for your desired library and copy the URL.
Here I am using “Kingfisher” for the demo, Paste the copied URL in the address bar and click Next.
Once the verification is complete below Interface will appear.
You will have three option to choose from
Here in the demo, I’ve chosen the latest version i.e 5.15.0. After selecting the rule click Next, and the download will begin. Once the download is complete the following interface will appear wherein you can just click Finish.
And now the dependency is successfully added to your project. Yayyyy!!!!
Let’s test and check the added dependency works well in the project.
Update the Package
Package Storage Location
Unlike cocoa-pods, it doesn’t download the dependency source to your project location. Check the below screenshot of the dependency location, this is where the dependencies are being cached.
Configuration of Dependency
- The package information is stored inside the .xcodeproj file.
- Check the package content of .xcodeproj (Right Click on .xcodeproj and Click on “Show Package Contents”)
- Check package content of .xcworkspace (Right Click on .xcworkspace and Click on “Show Package Contents”)
- xcshareddata -> swiftpm -> Package.resolved (Same as Podfile.lock in cocoapods)
Cocoapods and SPM can be used together
Once you are done installing the pods, now you have to use .xcworkspace
In the below screenshot you can see that I am using Kingfisher package and Alamofire pod.
If you enjoyed this article, share it with your friends and colleagues! Peace.