Integrate Cocoapods in Xcode: In any programming language we need to use old created functions or whole functionality that is already created earlier by us or by someone else so that and time and energy can be saved. Nowdays we call it as third party libraries that are created to perform particular functionality.
Integrate Cocoapods – Overview
Before using someone else code we must read its guide lines that mentioned in its source code. Third party libraries can be in many ways in our project. There are two methods by which you can use third party library in xcode first one is directly download your library codes and paste it in your project and connect it this is what we were using earlier. Second one is by cocoapods methods that is latest and majorly nowdays developer use this technique for integrating third party libraries to projects. Its is very simple and most accepted way to integrate any third party library.
INTEGRATE COCOAPODS IN YOUR XCODE PROJECT – STEPWISE GUIDE
For integration Cocoapods , First read its instruction of library almost for all library you will find instruction.
Open terminal in your mac or macbook by pressing control key + space button and then type terminal and you will find terminal there in search result after that click on terminal and it will open.x
Write in your terminal
$ sudo gem install cocoapods press enter then
you need sudo to cocoapods install but it will not need after install of cocoapods.
Now you are ready to integrate your third party dependencies
write in your terminal now
cd ~/Path/To/Project_folder Press enter then it will lead terminal to your project directory.
Now write initialization code in your terminal
Now we will open pod file that had been initialized by us in previous step by writing this code
open -a Xcode Podfile press enter then
Now your podfile will be opened and it will look like
< # Uncomment the next line to define a global platform for your project # platform :ios, ‘9.0’ target ‘cocoaExampleProject’ do # Comment the next line if you’re not using Swift and don’t want to use dynamic frameworks use_frameworks! # Pods for cocoaExampleProject end >
Now add dependency name and version number in code like for eample we use AFNetworking add its pod under target line in podFile code like
“target ‘cocoaExampleProject’ do ”
“pod ‘Alamofire’, ‘4.4.0’”
After its completion, close this podFile and changes will save.
Write installation of pod code in terminal
after pressing enter you can see its download has been started.
After its completion close the terminal and then you will see where your .xcodeproj file is present there new file is generated which is of type .xcworkspace now open that and you will see your third party dependency in pod file in xcode its added there.
Cocoapods Integration Advantages
- Library that you are integrating through cocoapods may need of some dependencies and that thing will be take care by cocoapods.
- Removing any installed library is no head ache in cocoapods integrated projects in comparison to library files added project. In library files project you have to manually delete each files from project.
- Replacing any library is also simple and updating version of library is also no headache now as cocoapods handles this.
Read More –