Xcode Dependency Management Using CocoaPods
September 10, 2014
I’ve been using Parse as a back-end for several of my iOS projects. Parse is a great service that makes it really easy to get everything up and running quickly. The only downside is that in addition to its SDK, Parse also requires you to install a lot of additional libraries to your project. To its credit, the company does a really nice job on its site of walking you through getting everything set up, and, if you’re starting from scratch, Parse will even generate a base template for you. But what if you’ve got a bunch of other dependencies as well?
That is where CocoaPods comes in.
CocoaPods is your one-stop shop for managing all your Xcode project’s dependencies. To install CocoaPods, open up a terminal window and type:
Now that you’ve got CocoaPods installed, it’s time to use it to manage the dependencies in one of your Xcode projects. For our purposes, I’m going to create a new single-view iPhone application in Xcode called “CocoaPodsTest” and save it to my desktop. Once the project has been created, close Xcode, head back over to your terminal window, navigate to the Xcode project you just created and then enter:
Now, if you look in your project directory, you’ll see that CocoaPods has created a file called “Podfile.” This is the file that CocoaPods uses to determine what dependencies to install. Open it up in your favorite text editor. For demonstration purposes, let’s include AFNetworking and Parse in our project. The Podfile should look something like this:
Save and close the Podfile and then head back to the command line and type:
What CocoaPods does is create an Xcode project called “Pods” with all of the dependencies that you’ve specified, then it takes that project and your original project and puts them both in an Xcode workspace and links them up. Going forward, you’ll now open the CocoaPodsTest.xcworkspace instead of your original CocoaPodsTest.xcodeproj.
If you need to remove a framework, simply remove it from your Podfile, rerun “pod install” and CocoaPods will take care of it.
And that’s all there is to it! If you’d like more info on CocoaPods, or Parse for that matter, you can find it below.