Yes, remember when we tried to add AFNetworking to our project or core plot.... It was a procedure of certain steps. Now, with Cocoa Pods is one and only step!
Cocoa Pods came to make our life easier.
Cocoa Pods is an Objective C library manager that manages library dependencies for your Xcode project. The goals are:
- Make working with dependencies simple.
- Improve library discoverability and engagement by providing an ecosystem that facilitates this
So using Libraries would be just a game.
Let's start with Pods now.
First install Command Line Tools for XCode. How?
Xcode includes a "Downloads" preference pane to install optional components. Open this pane by clicking the "Xcode" button in the top left of the screen, then click "Preferences", then click "Downloads". Choose Components Tab and click the install button of the Command Line Tools.
Open your terminal and type:
sudo gem update --system
sudo gem install cocoapods
Now, go to your Xcode project directory and create a text file named Podfile. A Podfile is the file that lists the dependencies of your application, which is usually located in the root of your project.
Navigate to the folder using the appropriate commands on your terminal and then type:
open -e Podfile
If everything is ok, TextEdit will open to an empty text file. Type inside TextEdit for example:
platform :ios pod 'JSONKit', pod 'AFNetworking', '1.0'
With this Podfile you will add to your project JSONKit (the most recent version) and AFNetworking version 1.0. At the beginning you define your platform (you can define osx as well). More about Podfiles you can find here.
Let's get back to our example. Save and Close TextEdit. In your terminal type:
If the procedure ended without error we are ready. Open your project folder and you will discover a new file. This is <yourProjectName>.xcworkspace
This is the workspace where CocoaPods stores all the libraries dependencies. From now on, you will use only this workspace.
That's it. If you need an additional library just add the appropriate line to your Podfile (use the CocoaPods site to find all the available pods), save it and type in your terminal:
For a more detailed guide, please read Marcelo's Fabri great tutorial "Introduction to CocoaPods"
In case that you try to add AFNetworking with a Podfile like
platform :ios pod 'AFNetworking'
and when you execute
you get an error like
[!] The platform of the target `Pods` (iOS 4.3) is not compatible with `AFNetworking (1.3.1)` which has a minimum requirement of OS X 10.7 - iOS 5.0.
you'd better compose a Podfile like:
platform :ios, '6.1' pod 'AFNetworking'
cause AFNetworking requires iOS 5+
Then everything will install fine!