CocoaPods is a dependency manager built on Ruby. It has thousands of libraries and more than a million of apps which helps to scale our project in a graceful and stylish manner. It saves a lot of time when dealing with various dependencies in project.
To install CocoaPods do following steps:
1- Open terminal and write the command
sudo gem install cocoapods
Once you are done, you’ll be asked to enter you system password. Enter your system password, if asked
2- To complete the pod setup enter the following command
pod setup --verbose
It may take time as it clones the CocaPods master repo into your subdirectoryPath/.cocoapods on your system.
With the above steps you are done with cocoa pods installation. Now it's a time to Install dependency in your project. To add dependency start following steps mentioned below:
1- Close Xcode and give complete path or your project in terminal using cd command:
2- Initialise pod using command
Above command will create the Podfile for the project.
3- Now either you can manually open the pod file created in step #4 or by typing command in terminal as:
open -a Xcode Podfile
This’ll open the pod file for you.
4 Replace the commented lines with the following code:
platform :ios, 9.0
and so on...
This tells Cocoapods that our project is targeting to 9.0. while 'use_frameworks' means we are using frameworks instead of static libraries.
5- Now you can add first dependency like below:
We are using 'Crashlytics' for example, you can use other dependency of your choice/requirement.
6- Now command the cocoa pods to install the dependencies for the project.
Once you are done with the above command you’ll be seeing few output on your screen like :
as so on……
9- Once the dependency installation is done you’ll see that cocoa pods has created a new ProjectName.XCWorkSpace file and a pods folder in the project folder path.
That’s all and your are done with dependency installation also.
From now you've to use ProjectName.XCWorkSpace file instead of ProjectName.XCode. You can add other dependencies in same manner by just opening the pod file and add dependency pod(s) over there.
This way you can save a lot of your time and effort for using dependencies in project. It makes addition, deletion and modification much easy and simple.