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.
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 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
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:
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
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.
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.