How to Install CocoaPods In Xcode

Fully updated for CocoaPods 0.31 and iOS 7

In this guide, you’ll understand how to use a well-known reliance control device known as CocoaPods.

But wait! What is a reliance control device and why do you need one?
As an iOS designer, you certainly use a lot of rule created by others, in the form of collections. Just think about how challenging it would be if you had to apply everything from scratch!

Without a reliance control device, you might basically add each library’s rule to your venture. However, this has several disadvantages:

  • Library rule is saved within your venture, spending area.
  • There’s no main position where you can see all collections that are available.
  • It can be hard to discover and upgrade a collection to a new edition, especially if several collections need to be modified together.
  • Downloading and such as collections within your venture may entice you to create changes to the downloadable rule and just keep it there (making it more complicated to upgrade them later).


A reliance control device can help you get over these problems. It will bring collection resource rule, take care of dependencies between collections, and even make and sustain the right atmosphere to develop your venture with the lowest of complications.

You’ll get arms on experience using CocoaPods for reliance control in this guide. 

Particularly, you will make an app that uses several open-source collections to bring and show details from a well-known tv and film details site, trakt.tv.


CocoaPods will make this venture much simpler. Study on to see for yourself!


Getting Started

Before you begin: This tutorial assumes you are familiar with Xcode, working with the command line, using AFNetworking, and the JSON format. If you’re completely new to any of these (a basic understanding should be okay), you should refer to the other tutorials on this site first.
To get began, you first need to set up CocoaPods. CocoaPods operates on Dark red, yet that’s the only reliance it has. Luckily, all latest editions of Mac OS X (since OS X 10.7 Lion) deliver with Dark red already set up. So all you need to do is upgrade RubyGems (just to create sure you have a latest version).

To do so, start International airport and kind the following command:
sudo gem update --system
Enter your password when requested. The Terminal output should look something like this:
Terminal Output
This upgrade may take a little while, so be individual and provides it a few moments to finish. You can also anticipate some certification in the International airport screen about the newest version; you can neglect this for now.

Next, you need to set up CocoaPods. Kind this control in International airport to do so:


sudo gem install cocoapods
You may get this prompt during the install process:
rake's executable "rake" conflicts with /usr/bin/rake
Overwrite the executable? [yN]
If so, just enter y to continue. (This warning is raised because the rake gem is updated as part of the install process. You can safely ignore it.)
Lastly, enter this command in Terminal to complete the setup of CocoaPods:
pod setup
This process will likely take a while as this command clones the CocoaPods Specs repository into~/.cocoapods/ on your computer.
Great, you’re now setup to use CocoaPods!
Now, close Xcode.


Installing Your First Dependency

Open Terminal and navigate to the directory containing your ShowTracker project by using the cd command:
cd ~/Path/To/Folder/Containing/ShowTracker
Next enter this command:
pod init
This will create a default Podfile for your project. The Podfile is where you define the dependencies your project relies on.
open -a Xcode Podfile
Note: You shouldn’t use TextEdit to edit the pod file because TextEdit likes to replace standard quotes with more graphically appealing quotes. This can cause CocoaPods to get confused and display errors, so it’s best to just use Xcode or another programming text editor.
The default Podfile should look like this:
# Uncomment this line to define a global platform for your project
# platform :ios, "6.0"
 
target "ShowTracker" do
 
end
Replace # platform :ios, "6.0" with the following:
platform :ios, "7.0"


It’s finally time to add your first dependency using CocoaPods! Copy and paste the following into your pod file, right after target "ShowTracker" do:
pod 'AFNetworking', '2.2.1'
This tells CocoaPods that you want to include AFNetworking version 2.2.1 (the latest as of the writing of this tutorial) as a dependency for your project.
You now need to tell CocoaPods to “install” the dependencies for your project. Enter the following command in Terminal to do so (making sure that you’re still in the directory containing the ShowTracker project and Podfile):
pod install
You should see output similar to the following:
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (2.2.1)
Generating Pods project
Integrating client project
It might also tell you something like this:
[!] From now on use `ShowTracker.xcworkspace`.
If you type ls now (or browse to the project folder using Finder), you’ll see that CocoaPods created a Pods folder – where it stores all dependencies – and ShowTracker.xcworkspace.
VERY IMPORTANT!
From now on, as the command-line warning mentioned, you must always open the workspace (ShowTracker.xcworkspace) and not the project!