Thursday, September 25, 2014

CocoaPods

Cocoapods is the dependency manager tool to manage library dependencies in Objective C projects. It will fetch library source code, resolve dependencies between libraries and create, maintain the right environment to build the project with minimum hassle.

CocoaPods can download code from Github & copy it to your project. You don't need to do this manually.

Basically, CocoaPods is built with Ruby and installable with default Ruby in OSX.

Following are the steps to install cocoapods-

1) Update the RubyGems
$ sudo gem update --system

2) Write this command in terminal to install the gem-
$ sudo gem install cocoapods


Note- During this process RubyGems might ask you if you want to overwrite the rake executable. This warning is raised because the rake gem will be updated as part of this process. Simply confirm by typing y.

3) Setup the cocoapods
$ pod setup

Installing the dependency-

1) Create the empty project & open it in terminal or open the existing project in terminal.

$ cd <pojectpath>

2) Create pod file. This pod file will include all the dependencies for the project.
$ pod init

3) Now,open the pod file & add the library with version number for installation.

target "ProjectName" do

pod 'AFNetworking', '2.2.1' // add this line to pod file to download AFNetworking source code

end


4) Install the pod file. This command will install the dependency for the project & create the workspace. Now you have to use this workspace instead of project file.
$ pod install

Note- If you want to delete the workspace you can use the given command to delete the workspace from the project.
$ rm -rf <workspaceName>