One of the few things that I find really annoying about developing apps for the iOS platform is how cumbersome it is to include third party libraries in your projects. Depending on the complexity of the library (e.g. its respective dependencies and transitive dependencies) and the effort the authors put into the consumability of their library, the steps required to add a library to your project range from just copying a few files into your source folder to a whopping two-page description of drag’n’drop wizardry.
Well, it turns out there finally is a solution for us Cocoa developers – CocoaPods. Getting started with CocoaPods is really easy and once you started using it, you won’t look back again.
CocoaPods itself is distributed as a Ruby gem, so installing it is as simple as:
Using CocoaPods to manage your project’s dependencies is a two-step process:
- Specify the dependency in you project’s dependency specification file,
Let me illustrate this by way of a simple example. Let’s assume you want to build an application with the awesome RestKit library. If you have used RestKit before, you know that adding it to your project is a rather involved process. Over the years, it has become significantly easier, but it still needs a very detailed installation instruction with lots of screenshots – check out their wiki page.
With CocoaPods, all you need to do is this:
- Create a new empty project, naming it
- In your project folder, create a new file,
- Fill in the following information:
1 2 3 4 5 6 7 8
pod install RestEasyWithCocoaPods.xcodeproj
- Open the newly created workspace,
- Add the RestKit headers to
1 2 3 4 5
- Done. Go and build awesome stuff with RestKit (more on this in another post).
Where to go from here
Wasn’t that a lot easier than all the other ways to install third party libraries?
If you are curious which libraries are supported by CocoaPods, go to CocoaPods.org – they have a nice little UI for searching their pod specification repository. If you are more include to using the command line, you are welcome to use
pod search <yoursearchterm> to search for a specific library.
If your preferred library is not yet supported, why not help them out and build a pod spec? CocoaPods itself and the pod spec repository are hosted on Github, so adding new pod specifications is really easy. The CocoaPods wiki has a section on creating and publishing new podspec files.
Now go and create awesome stuff!