Mobile Development

CocoaPods

http://cocoapods.org

CocoaPods is a third-party dependancy manager for Xcode. It is a free utility that was created using Ruby. You install it via Terminal and configure individual Pods using a text editor. 'Pods' refer to third-party libraries that you might want to install. After the first installation of a Pod, CocoaPods will convert your Xcode project into a workspace, which should be used for all subsequent development.

Definitions

Let's frame our discussion with the terms you will encounter when using CocoaPods:

  • CocoaPods - Depedency manager for Xcode
  • Pods - A collection of instructions consumed by CocoaPods to download and install third-party libraries
  • Podfile - Instructions contained within a text file, used by CocoaPods to install, update and remove pods
  • Ruby - An OO language that was used to develop CocoaPods
  • Gem - RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries [2]

Installation of CocoaPods

Installation of CocoaPods involves opening Terminal and entering a single command.

  1. Open Terminal
  2. Type
sudo gem install cocoapods
  1. That's it!

Finding and installing Pods

Let's say you want to install Fabric by Twitter.

Go to http://cocoapods.org.

Type "Fabric" in the search bar:

Copy the pod string by selecting the clipboard icon (as seen above).

Go to your project directory in a Terminal window and type:

pod init

Open your favorite text editing utility (as seen below):

nano Podfile

Enter the Fabric pod string:

pod 'Fabric', '~> 1.1'

Close your text editor and type:

pod install

That's it! CocoaPods will handle downloading all necessary pods, install them and configure your project to handle this and any required frameworks.

Maintaining Pods

Occasionally, pods will be updated with new versions. To update to the latest, you simple need to run the installation script again.

pod install

Removing Pods

To remove a Pod, edit your Podfile with the text editor of your choice. Delete the line that represents the pod you'd like to uninstall. When complete, type

pod install

Notice a pattern? :) The 'pod install' command is a one-stop shop for installing and updating your pods.

References

[1] CocoaPods http://cocoapods.org

[2] RubyGems http://en.wikipedia.org/wiki/RubyGems