Guide to working with CocoaPods

Become a Subscriber

CocoaPods are great for dependency management in Xcode projects. If you’ve ever worked with gems in ruby or npm with Node.js, then you are probably already familiar with how much time and energy a package manager can save. This guide walks you through using CocoaPods as well as common mistakes and errors and how to overcome them.

Setting up Cocoapods on project

You should be in the root of your Xcode project (where the .xcodeproject file lives) to execute these commands. Make sure you use git before you start using CocoaPods, just in case!

pod init

This command will simply create a Podfile for you in the directory. This file is what CocoaPods looks for in order to index and manage your dependencies. Now look at your Podfile in your editor of choice. You should see something similar to this (note: the word ‘Rainbows’ below would instead show your Xcode project name):

# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
# use_frameworks!

target 'Rainbows' do

target 'RainbowsTests' do

target 'RainbowsUITests' do

Now you can simply list out pod dependencies just like you would with ruby gems and bundler:

target 'Rainbows' do
  pod 'MK', '~> 1.0'

Now you are ready to actually build out your project:

pod install