First foray into CocoaPods

CocoaPods is the dependency manager for Objective-C projects. It has thousands of libraries and can help you scale your projects elegantly.

I’m working on updating an enterprise iOS application.  As part of that update, I eliminated dependancies on several third party libraries, and the remaining libraries I wanted to manage using CocoaPods.  Otherwise, the situation was that the source code for those libraries had just been dumped into the project several years ago, and there was no easy way of knowing what version of the libraries was being used nor a sane way of keeping the libraries updated. Using CocoaPods was surprisingly easy, but there were a few gotchas I ran into since I was integrating this into an existing project.  I thought I would share in case there are any other newbies out there who run into similar issues.  Note this isn’t meant as a detailed tutorial, for that I recommend you visit the links at the end of this post under “References/Resources”.

Step 1: Install CocoaPods

CocoaPods is built on Ruby. So it turns out, Ruby is included in MacOSX, and you don’t even need to update to the latest version or anything; in fact CocoaPods recommends you use the standard Ruby install.  In this respect it’s a lot simpler than dealing with some Java projects, where you need to update your JVM, deal with multiple JVM’s on your machine, updating your classpath, etc.  Literally all you need to do is open terminal and type in one line:

$ sudo gem install cocoapods

Step 2: Create a Podfile So for this step, I wasn’t sure what my Podfile should look like, e.g. should I assume a file extension of .podfile, etc.?  So the safest thing was to let CocoaPods create it for me.  This can be done using the “touch” command.  In terminal, cd to your project root directory and type

$ touch Podfile

Now for me, this created an empty Podfile, so I had to fill in the required content manually. In my case, this meant adding this as the first line in the Podfile:

platform :ios, :deployment_target => "8.0"

The deployment target should match your project settings in Xcode.

Step 3: Add the libraries you want to manage with CocoaPods

Go to and search for the library you want to use, then copy/paste the library name into your Podfile.  For example, for Google Analytics I added:

pod 'GoogleAnalytics-iOS-SDK'

save your Podfile and then run

$ pod install

From now on, whenever you open your project in Xcode, make sure you are opening the workspace file (.xcworkspace) and not the project file (.xcodeproj).  This way Xcode will properly include CocoaPods and find all your library dependancies. At this point, in theory you should be good to go.  In my case, though, I still couldn’t get my project to compile.  I was getting a “library not found for -lPods…” error.  I resolved it by going into the project Build Settings and setting the option for Build Active Architecture Only to “Yes”.

References / Resources:

Fuad Kamal

With a background in biotechnology, Fuad began his career developing assays and cutting edge technologies around HIV research. From there he shifted into the bioinformatics arena, where he developed innovative information systems in Perl. He started playing with the Flash platform around the time Flash 4 was released, and later developed the flash interface for the Flight Information Display System (FIDS) that you see at pretty much every major airport around the world today. Fuad loves delving into new technologies and pushing technologies in novel directions. Currently he is focused on providing mobile strategy & development for the Health & Fitness markets. He is an iOS developer, teaches an Android & Kotlin college course, and is currently writing The Kotlin Book Fuad has often applied principals he learned from his study of the martial arts to mentoring others as well as taking a unique approach to problem solving. He has found that quite often, the barriers we set before us are more mental than anything else, and the key to overcoming them lies in understanding this concept.

Click Here to Leave a Comment Below

Leave a Reply:

%d bloggers like this: