How I learned XCode - Package Dependencies vs Cocoapods
About me
One of the greatest days in learning to make apps is the day you find out how to add third party libraries to your project. Yes, there's a lot of value in building things yourself, but there are many great packages out there that can dramatically speed up your development, and let you focus on delivering a great experience to your users.
Why I wanted to learn XCode - Package Dependencies vs Cocoapods
Cocoapods is great, but what if you could add a dependency to your XCode project without having to go to the command line, edit a podfile, and then wait while everything loads? Well, Apple recently added a built in package dependency manager to XCode. The first time I used it, I was sold.
How I approached learning XCode - Package Dependencies vs Cocoapods
I wasn't even really sure what it was called, but I'd heard on the Sean Allen YouTube channel that it was possible. I googled for a bit, and then found the article on Apple.com.
Challenges I faced
It wasn't entirely clear how it was supposed to work, or at least it wasn't clear to me. Since it was new, it took some work to find what to search for and how to use it.
Key takeaways
Here's the general process:
- Identify the package that you want to add. For example: SDWebImage.
- Find the GitHub link. With SDWebImage: https://github.com/SDWebImage/SDWebImage
- Open your project in XCode
- Go to: File > Swift Packages > Add Package Dependency...
- Paste the Github link into the "Enter package repository URL" text field
- Click Next
- Choose which version. The latest is automatically selected
- Click Next
- Choose which parts of the package you want
- Click Finish.
That's it! Make sure you use the "import" statement in files in which you use the library.
Tips and advice
Pretty simple, and makes your life easier!
Final thoughts and next steps
I love it when things become a lot easier. This is one of those things! Next up - I want to create my own Swift package. I'm working on a few ideas for doing just that!