The Magic Of Cocoapods

2013-07-06

Hmm… among all posts that I have written this one seems that will be most helpful for you.logoYes, remember when we tried to add AFNetworking to our project or core plot…. It was a procedure of certain steps. Now, with Cocoa Pods is one and only step! Cocoa Pods came to make our life easier. Cocoa Pods is an Objective C library manager that??manages library dependencies for your Xcode project. The goals are:

  1. Make working with dependencies simple.
  2. Improve library discoverability and engagement by providing an ecosystem that facilitates this

So using Libraries would be just a game. Let’s start with Pods now. First install Command Line Tools for XCode. How? Xcode includes a “Downloads” preference pane to install optional components. Open this pane by clicking the “Xcode” button in the top left of the screen, then click “Preferences”, then click “Downloads”. Choose Components Tab and click the install button of the Command Line Tools. Open your terminal and type: sudo gem update --systemthen type: sudo gem install cocoapodsthe type: pod setupThat’s it! Now, go to your Xcode project directory and create a text file named Podfile. A Podfile??is the file that lists the dependencies of your application, which is usually located in the root of your project. Navigate to the folder using the appropriate commands on your terminal and then type:

touch Podfile``open -e Podfile

If everything is ok, TextEdit will open to an empty text file.??Type inside TextEdit for example: [sourcecode language=“objc”] platform :ios pod ‘JSONKit’, pod ‘AFNetworking’, ‘1.0’ [/sourcecode] With this Podfile you will add to your project JSONKit (the most recent version) and AFNetworking version 1.0. At the beginning you define your platform (you can define osx as well). ??More about Podfiles you can find here. Let’s get back to our example. ??Save and Close TextEdit. ??In your terminal type: pod installIf the procedure ended without error we are ready. Open your project folder and you will discover a new file. This is <yourProjectName>.xcworkspace??This is the workspace where CocoaPods stores all the libraries dependencies. From now on, you will use only this workspace. That’s it. If you need an additional library just add the appropriate line to your Podfile (use the CocoaPods site to find all the available pods), save it and type in your terminal: pod installFor a more detailed guide, please read Marcelo’s Fabri great tutorial “Introduction to CocoaPods” Enjoy! Added 28/7/2013In case that you try to add AFNetworking with a Podfile like [sourcecode language=“objc”] platform :ios pod ‘AFNetworking’ [/sourcecode] and when you execute pod installyou get an error like [!] The platform of the targetPods(iOS 4.3) is not compatible withAFNetworking (1.3.1)which has a minimum requirement of OS X 10.7 - iOS 5.0.you’d better compose a Podfile like: [sourcecode language=“objc”] platform :ios, ‘6.1’ pod ‘AFNetworking’ [/sourcecode] cause AFNetworking requires iOS 5+ Then everything will install fine!