CocoaPods: How To

Hello and Welcome!

For those who are not already familiar with CocoaPods, here’s a brief about what and how to use them.

1. What is/are CocoaPods?
 “CocoaPods is the dependency manager for Swift and Objective-C Cocoa projects. It has thousands of libraries and can help you scale your projects elegantly.”

CocoaPods helps you to easily integrate and manage dependencies with third party libraries within your projects.
Which means, if you a project A that uses a library B, instead of adding a libB.a (a library file) into your project, you can define the library’s source (a GitHub link) in the pod file (that is created using CocoaPods) and installing the pod will download the library for you; create a workspace; and integrate the library and your project in the workspace.
Once setup, all you need to do is to open the *Workspace and tap build. And voila! now you have integrated a library! 🙂

According to its website, CocoaPods is “the best way to manage library dependencies in Objective-C projects.” and you’ll soon know it sure is! 🙂

So lets get started. Lets install CocoaPods.

Getting Started

Step 1: Update RubyGems
– CocoaPods runs on Ruby – (You will have Ruby preinstalled in newer Mac OS X; RubyGems is a package manager for the Ruby programming language)
<Just to be up to date to save some trouble that you might run into in case you are using an older version>

$ sudo gem update --verbose

sudo – will prompt for admin user password. You will have to supply this to continue with the update.
— verbose will print all logs.
(Press ‘Y’ to continue any override errors.)
Now, grab a cup of coffee while this completes.

Step 2: Install CocoaPods

$ sudo gem install cocoapods --verbose

Step 3: Setup CocoaPods

$ pod setup --verbose

This does the housekeeping stuff. This is required for running any CocoaPod commands.

Step 4: Create or Open your Xcode project directory.
Say I have a project named office365Demo.
If not create one (a simple single screen app would do). And lets call it office365Demo.

In terminal navigate to the folder containing office365Demo.xcodeproj

$ cd <folderpath>

Step 5: Create a Pod file.
A Pod file is what contains the details about the dependant libraries used in your project .

$ pod init

Step 6: Update the Pod file.
Open the created Pod file in Xcode. (or VI editor in terminal)

Warning! Some editors might cause issues adding unreadable characters.

Specify the dependant library(s) in the Pod file.

Since the following blog will be on Office365 iOS SDK, we will try adding a dependancy to the Office 365 library.Add the below two lines to the Pod file.

It contains two libraries namely, Office365 and ADALiOS.
(ADAL to handle authentication and Office365 for convenience classes)
target 'office365Demo' do
pod 'Office365', '=0.7.0'
pod 'ADALiOS', '=1.0.0'

Step 7: Install Pod
Make sure you are still in the project folder where the Pod file was created.

$ pod install --verbose

This will download the dependant libraries from GitHub to the project folder and will create a workspace by integrating the project with the library.
At the end of the installation it might show a warning that reads like:
[!] From now on use `office365Demo.xcworkspace`.

*IMPORTANT: Using the .xcodeproj will not work and you will have to use the .xcworkspace to build the project.

Step 8: Open the xcworkspace
Build the application. Hopefully without any errors. 🙂

If you are getting build errors that the libraries added through CocoaPods are not available. Check the below setting in Xcode.

  1. Go to File -> Project Settings. (Xcode Preferences -> Locations)
  2. Click the Advanced button under Derived Data Location.
  3. Under build location select Custom: [Relative to Workspace].


  1. CocoaPods
  2. CocoaPods Blog
  3. CocoaPods Guides
  4. Podfile Syntax

Microsoft Office 365 iOS SDK:

  1. Dev Center
  2. GitHub Office365 SDK
  3. GitHub Office365 Wiki

Sample Tutorial:

Detailed Read:

Sharing your open source library through CocoaPods:

Now. So far you have you have learnt how to use CocoaPod to add dependancy of a third party library to your project. You might be wondering then how to add your own library to CocoaPods for others to use it.  For that you can follow the below blog:



Creating a CocoaPod


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s