The Cookbook

Xcode development using Cocoapods

Problem

Manage 3rd party libraries in Objective-C projects.

Solution

Use Cocoapods for library management in Objective-C projects.

Step 1

Install cocoapods gem and initiliaze.

1
2
3
4
$ gem install cocoapods
# If you are using rbenv don't forget to rehash
$ rbenv rehash
$ pod setup

Step 2

Create a Podfile and list dependencies.

1
2
$ cd ~/foo    # your xcode project root folder
$ vim Podfile
1
2
3
# ~/foo/Podfile
platform :ios, '5.0'            # deployment target SDK
pod 'AFNetworking', '~> 1.2.0'  # means we need AFNetworking version 1.2.0 or higher

Step 3

Now install dependencies.

1
2
3
4
5
6
7
8
$ pod install
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (1.2.1)
Generating Pods project
Integrating client project

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

Cocoapods creates an Xcode workspace and Pods static library project, then links it with you project. All your dependencies will be available through that library. As the output suggests, you will use foo.xcworspace from now on.

1
$ open foo.xcworkspace

Discussion

Cocoapods certainly makes it easier to manage libraries in your project. You can search the library you want to use.

1
$ pod search TestFlightSDK

As well as Xcode workspaces have some advantages described in Xcode Concepts which we discuss in Core Data: Automate master data preloading.

Comments