Why do I want to reinvent the wheel? Why should I spend precious time writing code and solutions that was already written ? So that’s why it’s handy to use a dependence manager, like CocoaPods. If you don’t know what it is, here’s some enlightenment from Bryan Irace, that explains, in Objective C, the success of CocoaPods. I’m going to explain how to do it in your project. If you don’t have a project create one with this easy tutorial. And it’s nice to use gitHub to version, so if you don’t know how to do it, this is another easy tutorial about how to do it. The first thing you need to do is install the cocoa pods, if it isn’t installed in your mac. Just open the terminal and type: “sudo gem install cocoapods” (with no quotation marks). And then, it’s going to ask for your mac password and that’s it. It’s going to install the cocoa pods or update it to a recent version. Next step is to use it on our project. Just navigate to your project with ls and cd on the Terminal
and then type: “pod init” to initialise the pods and then “pod install” and then it will start installing, as it shows in the image below:
After the installation you will always open the projectName.xcworkspace to open your project, and you can open with the terminal if you want, you just need to type ( in the current folder you are in ) “open projectName.xcworkspace”. And you can use your dependency normally, like you would import any native class:
And to add any dependency, you just need to open the podfile, ok, because you typed “pod init” on your terminal, CocoaPods automatically created a file called Podfile with smart defaults. That means you just need to open in on xCode ( you’re already on terminal, why not write “open Podfile” and get done with it? 😉 ) type:
open -a Xcode Podfile
this is the print screen of what is written in the file
ok, now you’re going to write what library you will want before the target keyword :
pod 'NameOfTheLibrary', '~> version of the library' pod 'AFNetworking', '~> 2.0'
And what if the library is not included in a specs public database ( contained in the cocoapods ). Easy pizzy:
pod 'NameOfTheLibrary', :git => 'gitPath', :commit => 'Especific Commit'
pod 'Artsy+UILabels', :git => 'https://github.com/Artsy/Specs.git', :commit => '7088b16209'
Now you just need to install the new pod: “pod install“. And to make sure everything is ok: “pod update“. And it’s done.