Nowadays, most of the iOS Libraries have CocoaPods support and It is very easy to add a library to your project with CocoaPods.
If you are an iOS Developer, sooner or later a project with CocoaPods will find you. So lets learn it now and see how CocoaPods makes your project management easier.
First of all what is CocoaPods:
CocoaPods is the dependency manager for Objective-C projects. It has thousands of libraries and can help you scale your projects elegantly.
This means CocoaPods helps you to manage the libraries you use in your project. For more visit: http://cocoapods.org/
Step 1: Installation
CocoaPods is built with Ruby and is installable with the default Ruby available on OS X. We recommend you do this.
So open up your terminal in OS X and write this command:
$ sudo gem install cocoapods
OK now you are ready to go.
For more info about install process http://guides.cocoapods.org/using/getting-started.html#getting-started
Step 2: Create a Podfile
Podfile is a specific file for CocoaPods where you list the libraries you want to use in your project. To create a Podfile,
just create an empty text file named Podfile in your project directory.
Or you can run “$ pod init “ command in your project directory and cocoapods create a file for you with some features in it.
Both way simply creates Podfile for you, use the one that you find easy.
Step 3: List your libraries
Here is an example Podfile:
platform :ios, '7.0' pod 'AFNetworking', '~> 2.0' pod ‘pop’, ‘~> 1.0'
This Podfile shows that in this project AFNetworking and pop libraries will be used. You must write all the dependencies here, before you use in your project.
Step 4: Install the libraries
We are ready to install our dependencies in the Podfile. It is as easy as running
$ pod install
command on the project directory. ( Make sure your Podfile is also there )
Now if everything goes right as expected, you now have your libraries in your project. And one more file with xcworkspace extension.From now on you must open your project from that file (Xcode workspace).
Do not open your project from the file with xcodeproj extension if you want to use cocoapods.
Make sure you run “$ pod install” command every time you add or delete a new library to the Podfile.
Step 5: Use the libraries in the Project
Now you can import your libraries like:
and you are ready to go.
For more info visit cocoapods.org or follow them on Twitter @CocoaPods.
To find some cool libraries cocoacontrols.com and cocoapods.wantedly.com
I want to write this tutorial as simple as possible. If you have something to add, I will be happy to hear.