Skip to main content

CocoaPods

·2 mins

I recently attended a Cocoaheads meeting where I was introduced to CocoaPods. Since many of the people who read this blog develop Mac and iOS software, I figured I should share what I learned. Keep in mind I haven’t used CocoaPods yet so I can’t answer any questions on the technical details. Go to the CocoaPods site to learn more.

What Is CocoaPods? #

CocoaPods is a library dependency manager, which is a fancy way of saying it manages the libraries your app uses. If you’ve ever programmed in Ruby, you can think of CocoaPods as the Objective-C equivalent of Ruby gems.

Why should you care about CocoaPods? If your app uses third-party libraries and frameworks (anything other than Apple’s frameworks), CocoaPods makes working with those libraries and frameworks easier. Using third-party libraries without CocoaPods involves either cloning online repositories or downloading and installing the libraries manually. Both of these approaches make updating more difficult.

Using CocoaPods with Your Xcode Project #

To use CocoaPods with an Xcode project you must create a pod file and add it to your project. The pod file is a text file named Podfile that contains the libraries your project is going to use. The following example from the CocoaPods site shows a simple pod file for an iOS app:

platform :ios
pod 'JSONKit', '~> 1.4'
pod 'Reachability', '~> 3.0.0'

In this example the project depends on version 1.4 of the JSONKit library and version 3.0.0 of the Reachability library.

After creating the pod file, run the following command to install the dependencies:

pod install

Running the pod install command creates an Xcode workspace for your project that contains the dependencies. Open the workspace (not the project) to work on your project. In the Cocoaheads meeting I attended, the example used the Facebook SDK. Running the pod install command added the Facebook SDK to the workspace without having to install the SDK. Very cool. If you use open source libraries and frameworks in your Mac and iOS apps, you should check out CocoaPods.