The dependency manager for Objective-C – CocoaPods

Ruby has RubyGems, Objective-C has CocoaPods – open source libraries dependency manager project. Installation is simple:

sudo gem install cocoapods

Create xcode project and cd to project folder. Run commands below to create and open Podfile.

touch Podfile
open -e Podfile

Whats a Pod file? I would say Pod file is your library wishlist based on which CocoaPods automagically imports source files and sets project configuration for you. Lets assume we want to add RestKit framework to our project. Simply c&p code below to Podfile and save.

platform :ios, '5.0'
pod 'RestKit', '~>  0.20.0'

On http://cocoapods.org/ you can browse all pods. Now run install command.

pod install

You should see output similar to:

Analyzing dependencies
Downloading dependencies
Installing AFNetworking (1.3.3)
Installing RestKit (0.20.3)
Installing SOCKit (1.1)
Installing TransitionKit (1.1.1)
Generating Pods project
Integrating client project

[!] From now on use `DependencyManagerExample.xcworkspace`.

And that’s it. Complete project setup is automagically finished. You are now ready for coding part. This is the main purpose of dependency manager.

Git submodules vs CocoaPods

Developers usually complain that CocoaPods is missing one important feature – git submodules support within Pods source files. CocoaPods doesn’t need to have reference to git source because in this case versioning is based on .podspecs file. CocoaPods app don’t have a clue when or if one of the source files has been modified if its not declared in .podspecs. On other hand it would be convenient if a developer has ability to push changes directly from his workspace to source repository but that just not the case here for now.

For more information go to http://cocoapods.org/.

Leave a Reply

Your email address will not be published. Required fields are marked *