An Introduction to CocoaPods
Posted By : Gaurav Kumar | 12-May-2018
Today In this article, we are going to discuss what is CocoaPods and why we need CocoaPods. So let get started by what is CocoaPods. CocoaPods is an application dependency manager for Swift and Objective-C Cocoa projects. It has thousands of libraries and is used in over million of application.
The next question is why we need CocoaPods. CocoaPods make easy the life of developer by simply integrating the third library easily into our project. An application dependency manager let us add, remove and update any third library very easily and with less effort.
Before CocoaPods, how a developer is managing and integrating third-party library. There are a lot of steps involved in integrating third-party library manually. Let us point out some of the steps. And the steps are given below:
- Download and unzip files
- Drag framework and bundles to your project
- Link with new iOS libraries.
- Add Linker flags
- Go to step1!
CocoaPods is the superstar of iOS application development. Those people coming from android application development background, they can relate CocoaPods with Gradle. As we know that Gradle is also an application dependency manager and build tool. Those people coming from java application development background, they can relate CocoaPods with Maven.
So let get started with today agenda. And the agenda is
- Installing CocoaPods
- Initializing project for Pod
- Adding third party library
Installing
$
Once the CocoaPods is installed, we can check the version of CocoaPods by simply writing pod -version
Initializing project for
Since the project doesn’t contain Pod file. Because we didn’t initialize our project for Pod. The command for initializing Pod is
$ pod init
After above command is executed, then execute ls command to see the Pod file in our project. Since the Podfile doesn’t contain any dependency library by default.
Adding third-party library:- Adding third-party library to our project is as simple as easy. Suppose we know the exact name of the third-party library, in my case we are going to use swift networking library. And the library name is Alamofire. To add Alamofire library to our project, open Podfile by writing open Podfile. Once the Podfile is opened, we can write down the name of the library after target line of this file. We have to write down
pod ‘Alamofire’
Save and exit the Podfile. Next, we have to install the added library by writing
$ pod install
The above command downloaded the Alamofire with the latest version. We can also specify the version with the library name. For example
pod ‘Alamofire’, '~> 2.3'
Once the pod is successfully installed for
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Gaurav Kumar
Gaurav Kumar is a software developer having skill set in java and mobile application development.