Skip to content

June 29, 2012


Using CocoaPods to manage your dependencies

CocoaPods Logo

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.

Wouldn’t it be awesome if you could just specify a list of dependencies and be done? You might have heard of RubyGems, Maven, Ivy, NuGet or npm that bring dependency management to the worlds of Ruby, Java, .NET and JavaScript developers.

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:

[sudo] gem install cocoapods
pod setup


Using CocoaPods to manage your project’s dependencies is a two-step process:

  1. Specify the dependency in you project’s dependency specification file, Podfile
  2. Run pod install

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:

  1. Create a new empty project, naming it RestEasyWithCocoaPods
  2. In your project folder, create a new file, Podfile
  3. Fill in the following information:
    platform :ios
    dependency 'RestKit'
    dependency 'RestKit/UI'
    dependency 'RestKit/Network'
    dependency 'RestKit/ObjectMapping'                       
    dependency 'RestKit/ObjectMapping/CoreData'
    dependency 'RestKit/ObjectMapping/XML'
    dependency 'RestKit/ObjectMapping/JSON'
  4. Run pod install RestEasyWithCocoaPods.xcodeproj.
  5. Open the newly created workspace, RestEasyWithCocoaPods.xcworkspace
  6. Add the RestKit headers to RestEasyWithCocoaPods-Prefix.pch:
    #ifdef __OBJC__
        #import <UIKit/UIKit.h>
        #import <Foundation/Foundation.h>
        #import <RestKit/RestKit.h>
  7. 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 – 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!

Thanks for reading this post. Follow me on twitter here to be notified about updates and other posts I write. Or, subscribe to my RSS feed here. If you want to get in touch with me, use the contact form.

Fork me on GitHub