We in Terato Tech work in various projects from small scale to large scale enterprise application. Often while developing an application we need to use different library and resources. This time I’ll show you how to manage library dependancy for iOS with Cocoapods.

 

Why Cocoapods

Before Cocoapods the most common way to include external library to your iOS project is by linking static library and configure each of it to suit your need. It’s totally fine and if you already get used to it as how we get used to it, it’s not a big deal. However, Cocoapods simplify the process and managing library dependency become easier, so you can focus to build a great application without wasting your time to manage the library.

 

Installing Cocoapods

Installing Cocoapods is very straight forward. Cocoapods distributed as ruby gem and since your Mac has ruby preinstalled you only need to type these into your Terminal.

$ gem install cocoapods
$ pod setup

 

Configuring Podfile

Once it set, the next thing you do is creating Podfile inside your Xcode root directory and edit the content with the library you want to use.

Example of Podfile:
platform :ios,'5.1'
pod 'AFNetworking', '~>1.1.0'
pod 'JSONKit', '~> 1.4'

Save it and then type $ pod install in your Terminal. Wait till it’s done and now whenever you want to use your project you must open xcworkspace created by Cocoapods instead of xcodeproj.

Project with cocoapods

Sample project with cocoapods

 

Manage your dependency

This is where Cocoapods come in handy. Whenever you want to add or remove or update your library you simply edit the Podfile and run $ pod install in your terminal. Cocoapods will manage it for you.

 

Cons

So far there are only few cons I found while using Cocoapods.

  • Not every project/library has Cocoapods version
  • It has tendency to build every part of the library
  • Sometimes it’s overkill for small project

However, you can always create your own podspec and configure how it works for your project to eliminate the cons.

 

For further reading you can always refer to Cocoapods website and if you are into opensource lifestyle you can contribute to the project Cocoapods github repository

 

Cheers !!

One comment on Manage project dependency with Cocoapods

Hello there, anything to say? ;-)