If you need to add third party libraries in your XCode project, it will be very good decision to install Cocoapods because it is a dependency manager. It is built with Ruby. So it could be installed on any OS X, with default Ruby. The installation process is very easy. Just follow the given steps.
Step # 1 (Checking the CocoaPod version)
First you need to check whether the
cocoapod is already installed
in your MAC or not. To check it open the terminal
and write (like Image 1)
pod --version
or
gem which cocoapods
|
01. Checking Pod version |
The result should be the version number of installed
cocoapods. If it is not you have to install it or the version is not latest you need to update it. Otherwise you can jump to Step # 3
Step # 2 (Installing / Updating Cocoapods)
To install or update the
cocoapods write in
terminal (Image 02)
sudo gem install cocoapods
or for Mac OSX 10.11 El Capitan
sudo gem install -n /usr/local/bin cocoapods
|
02. Installing Cooapods |
Provide your password. It may take some time. Please wait until the response (Image 03). If you are installing the
cocopods for first time there could be lot of messages. Just check those messages for any errors. If you get an error something like "
activesupport requires Ruby version >= 2.2.2", that means your
activesupport is outdated or need to install
activesupport version 4. To install it just type in terminal (Image 04)
sudo gem install activesupport -v 4.2.6
|
03. Successfully installed cocoapods |
|
04. Installing ActiveSupport v4 |
Step # 3 (Setting up CocoaPods)
Wait for the success message. So now your the
cocopod is installed
in your MAC. Your next work is to
setup the
cocoapods master
repo. To do so write in
terminal
pod setup
After running this command in the terminal you can see a response like "Setting up
CocoaPods master
repo". Just wait for another response says "Setup completed". (Image 5a and Image 5b) There is an alternative command for doing the same work. That is
pod setup --verbose
|
05.(a) Cocoa Pod Setup |
|
05.(b)Cocoa Pod Setup Completion |
Step # 4 (Creating PodFile)
Now you can create
a podfile in your XCode project's directory. Get the project's directory and
cd to that directory in
terminal. Suppose I have a XCode project named "TestProjectForCocopods" and its root directory is "/Users/******/Documents/XCode_Project/TestProjectForCocopods". So in terminal
cd this directory like (Image 06)
cd /Users/******/Documents/XCode_Project/TestProjectForCocopods
Now type
pod init
|
06. cd to Project's directory |
Just wait for the success message. But if you get an error like "
LoadError - cannot load such file --nanamio" then you have to uninstall nanaimo. To do so, go to the home directory by typing only cd in your terminal
To uninstall nananimo, in terminal type (Image 07)
sudo gem uninstall nanaimo
Type your MAC's password there then select uninstall all versions of nanaimo. It will uninstall all versions of nanaimo apart from version number 0.2.3
|
07. Uninstalling nanaimo |
Now repeat this Step 4. After doing this, you can see a podfile in your XCode project's directory (Image 08).
|
08. New podfile created in the Project's folder |
Step # 5 (Adding & Installing dependency)
Now you have to add the your project's dependencies in this podfile. So just this podfile and add your dependencies. To open this podfile by terminal type (Image 09)
open -a Xcode Podfile
|
09. Opening the podfile using terminal |
Initially there will be some commands. Here you can add your project's dependencies. Suppose, you need to add "ASJOverflowButton" library in your project. So type pod 'ASJOverflowButton' in your
podfile (Image 10).
|
10. Adding project's dependencies |
Now come back to
terminal. Then type (Image 11)
pod install
|
11. Installing projects dependencies |
Wait for
response saying "Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed." This dependency number could be varied with the number of dependency you have added in the podfile. Now go to the folder where you have your Xcode project. Here you can see a new file with extension
.xcworkspace. Open this file in XCode and start writing code here.
|
12. A file with extension name .xcworkspace created |
No comments:
Post a Comment