CocoaPods is a powerful and at the same time elegant dependency management tool for Cocoa libraries that developers use in their iOS and MacOS X projects. As usual for Cocoa articles, we will focus on iOS development.

iOS developers like to use the work of other developers (3rd party developers). And as a rule, libraries come with source code. And usually we add the source code of the libraries to our project, once taking it from the developers repository. There are several drawbacks to this approach:
')
- It is sometimes difficult to keep track of library versions and their relationships with each other.
- There is no one common place where you can view a list of all available libraries. Of course, github is one of the major havens of opensource projects, but not the only
- It is always necessary to remember that the source code of such libraries needs to be updated. (part of the problem would be solved by means like git submodules )
- When you download source files and add to your project it is often tempting to change the library code locally, which in the future will create a headache when updating the library.
The CocoaPods addiction management tools help solve many of the problems mentioned. CocoaPods will deal with the dependencies between the libraries you use, download them, create and maintain the project structure in the proper form.
With CocoaPods, creating a project using third-party developments is much easier. And so, let's get started.
Getting started
According to the official
website , CocoaPods is the best tool for managing library dependencies in Objective-C projects.
Instead of downloading code from the library repository and copying to your project folder, we can provide CocoaPods the ability to do everything for us.
For example, we need to make an application that will communicate with the RESTfull API of a service using JSON.
The most popular library for working with HTTP requests is
AFNetworking (since ASIHTTPRequest was no longer supported).
First we need to install CocoaPods. CocoaPods is a Ruby project, and to our happiness, the Ruby interpreter comes as standard in MacOS. Ruby is the only CocoaPods dependency, and first we need to update the list of packages in the terminal by running the command:

Perhaps, for correct work, we will first need to update or install the Command Line Tools for Xcode. You can do this by going to Xcode> Preferences> Downloads> Components.
After the package list has been updated, we can install CocoaPods:
sudo gem install cocoapods &&
pod setup

CocoaPods installed.
Hello world
Create a new almost empty project File> New> Project ...> Single View Applciation, for example:


Add the first dependency
Well, here he is - the moment of truth. Add our first dependency to the project.
In the terminal, go to the project folder and do the following:
1) Creates a pod file

2) Add a library

As you can see, the dependency file format is pretty simple. We added a line with AFNetworking and indicated that we are interested in the latest, 0.10.0 version.
It details the format of the Pod-file.
3) We generate the initial environment, load the necessary files of both CocoaPods itself and the source codes of the libraries. And most importantly - will always keep them up to date:
pod install

After performing these simple procedures, we get a new draft of the project. Now you need to work with it through the generated xcworkspace. That is,
forget about the project file as an independent entity, only workspace!
open CocoaPodsExample.xcworkspace
This is what the project structure will look like.

Now you can easily connect AFNetworking.h and use this library as if you yourself just downloaded its sources and placed them in your project.

Actually, this is probably the main way to work with CocoaPods. Basic, minimal and simple.
File with dependencies can be supplemented by diluting a single AFNetworking:
pod 'SSToolkit'
pod 'AFNetworking', '> = 0.5.1'
pod 'CocoaLumberjack'
The essence does not change, the simplicity of the work does not disappear.
Here is a list of the most popular libraries available through CocoaPods:
- AFNetworking
- ASIHTTPRequest
- BlocksKit
- ConciseKit
- Coreplot
- EGOTableViewPullRefresh
- Facebook-iOS-SDK
- JSONKit
- MBProgressHUD
- Nimbus
- Quickdialog
- Reachability
- SFHFKeychainUtils
- ShareKit
CocoaPods clearly can be attributed to must have means in the arsenal of Cocoa-developer.
