CocoaPods is the dependency manager for the projects. It has number of libraries and can help you scale your projects easily. CocoaPods is built with Ruby and is installable with the default Ruby available on your mac machine. The main advantage of Cocoapods is that the libraries are hosted on other machine and you can easily integrate to your project by simply modifying the pod file and hit one command to install/update the pods (you can refer them to as your libraries or frameworks). Below are the steps to install Cocoapods and use them with your project
** Make sure you have installed/updated command line tool in your Mac machine. You can check this by opening Xcode, navigating the menu to Xcode > Preferences > Downloads > Components, finding Command Line Tools and select install/update.
If you see command line tools then install those first. If they are installed then please proceed further. Open terminal and execute below commands
1) sudo gem install cocoapods – This will installed cocoa pods in your mac machine.
For El Capitan OSX use –
sudo gem install -n /usr/local/bin cocoapods
The above command will ask for your system password, if any and will take some time. The terminal will show you a waring message please ignore this.
|Executing sudo gem install cocoapods in the terminal
|CocoaPod installed successfully
2) Set up pods with your Xcode project. Open terminal and type the change directory command
$ cd path of your XCode project root directory (where your ProjectName.xcodeproj file is placed)
$ pod setup – Setup Cocoapod master repo
$ touch podfile – create a blank pod file, it’s the place where you will write your libraries name you want to use in your project.
$ open -e podfile – will open pod file in text editor
write your libraries name as show below. Save and close text editor.
NOTE: Use ( control + ” ) button to add single quote at both end of library name. It should be shown as straight vertical line. Without control button it shall be added as curly single quote which will give error while installation of file.
$ pod install – install all the libraries written in the pod file
You should see output similar to the following:
Updating spec repo `master’
After successful downloading/installation of any single library, It will generate ProjectName.xcworkspace in your project root directory. From now use this workspace to open your project. When you open your project work space you will see Pod is also added as another Xcode project with your Xcode project. If you open Pod it will show all libraries.
For your next project your don’t need to install the cocoa pod again in your mac machine just open the terminal and setup the Pod in root directory of your Xcode project and always remember these 3 commands :
- 1. $ touch podfile
- 2. $ open -e podfile
- 3. $ pod install
To update Pod libraries : $ pod update
To check POD version : $ pod –version
To update CocoaPods : $ gem install cocoapods or use sudo at start if getting error “You don’t have write permissions for the /Library/Ruby/Gems/2.0.0 directory.”
NOTE: Article originally taken from below link