You can make app from scratch, its hard and sometimes you need libraries made by others. We simply add libraries to our project and doing that has some disadvantages like :
Wastage of space as whole library is stored in our project.
- Difficult to keep libraries upto date.
- You might change the code of downloaded library which will make it harder to update later.
- And libraries are every where no centre space.
So CocaoPods – a dependency management tool it overcome all these issues and more. You can use several libraries at ease. Its the best way to manage library dependencies in iOS Projects.
Lets start Installing CocoaPods to your iOS Project.
- First install Ruby : Open Terminal and run the following command
sudo gem update — system
Your mac comes with ruby installed you just need to update it. Then run the following commandsudo gem install cocoapods
This will start installing CocoaPods into your Mac.
pod setup — verbose
this process will take a few mins as it clones CocoaPods Master Spec repository into /.cocoapods on your mac The verbose option logs progress as the process runs.
- Creating podFile : podFile is where you define your project’s dependencies.
First Open Terminal then navigate your project directory by cd command :
open terminal type cd drag drop your project folder.
pod initthis will create a podFile for your project.open -a Xcode PodFilethis will open PodFile for your project in Xcode
You should not use TextEdit because it replaces standard quotes with graphically appealing typeset quotes. This cause CocoaPods confuse and there will be errors.
- Adding Libraries : in your PodFile write the followingplatform :ios, “8.0”
This tell CocoaPods that you targeting iOS 8 and will be using frameworks instead of library.
In order to use CocoaPods written in Swift, you must explicitly include use_frameworks! If you forget to mention this, and CocoaPods detects you’re trying to use a Swift CocoaPod, you’ll get an error when you try to install the pods.
Add your first dependency using CocoaPods. Add the following to your Podfile, inside the first target block.
pod ‘Alamofire’, ‘1.2.3′
This tells cocoapods that you want to include Alamofire version 1..2.3 as a dependency for your project.
now save and close your podfiel in xcode and run command.pod installthis will add pods to your project, when its done close Xcode and run your project using project.workspace.