-
Notifications
You must be signed in to change notification settings - Fork 472
Using CocoaPods
This guide covers 1) setting-up CocoaPods, and 2) adding and installing Pods into your Xcode project. By the end of it you'll be ready for guides on actually using the Pods you need.
- Basic level in Xcode
- Novice level in Terminal
- Install CocoaPods by typing the following commands into Terminal
gem update --system
gem install -n /usr/local/bin cocoapods # Install CocoaPods gem
pod setup # Clones the CocoaPods specs repo to ~/.cocoapods
- ☝️ NOTE If you are not able to install using
gem install -n /usr/local/bin cocoapods
, then try usingsudo
as shown in the following snippet.
sudo gem install -n /usr/local/bin cocoapods # Install CocoaPods gem
pod setup # Clones the CocoaPods specs repo to ~/.cocoapods
- Just close your Terminal window and re-open it to complete setup!
Note: If your Terminal gets stuck on pod setup
, see FAQ
First you need set your Terminal's Present Working Directory to the folder containing your XCode Project.
- Type the characters "
cd
" + space - Drag the folder containing your
.xcodeproject
file to your terminal, then hit your return key
CocoaPods uses a text file named Podfile
to define your project's Pods. To add your Podfile:
- Type
pod init
into your terminal - Type
open -a Xcode Podfile
and edit yourPodfile
in Xcode
- First, you can delete everything in this file
- Add
use_frameworks!
- Add a row for each Pod you're installing, then save
use_frameworks!
pod 'MBProgressHUD'
pod 'AFNetworking', '~> 2.0'
Note: Your Pods will be different. These are two examples.
- Next have CocoaPods install typing the following into terminal
pod install
Note: If pod install
is taking more than 60 seconds, see FAQ
After your first pod install
, CocoaPods will create a new .xcworkspace
file for you, which includes has your CocoaPods as well. Only use your .xcworkspace
from now on.
- Close your
.xcproject
file - Open your new
.xcworkspace
file, which you can find in your project's folder
If you later need to change your Podfile
to bring-in new Pods, simply run pod install
again.
In any Swift file where you want to use the library, you need to import it.
import UIKit
import MBProgressHUD
We're done! Now you can use your Pods– just follow the Pod maker's tutorials.
For example, now you can use your Pod in a ViewController.
class ViewController: UIViewController {
var progressHUD : MBProgressHUD!
...
}
Note: Your Pods will be different. This is one example.
If you experience absurdly long/ several minute waiting on pod setup
, or pod install
, you may try the following:
- Close your Terminal window, and open a new one
- Type the following commands
pod repo remove master
pod setup
- Now you can go back to step one and try again!
Answer: The Pod's developers will usually tell you what to write on their website.
- See Codepath's in-depth on CocoaPods, which includes links to major CocoaPods directories.