Tools & releasesHistorical technical note
Installing and using CocoaPods for iOS development
Starting with Ruby and CocoaPods installation, this article explains how to find dependencies, write a Podfile, install pods and open the generated workspace. It also records a fix for header completion, illustrating an early iOS dependency-management workflow.
Originally credited to Bison. Content is retained as published.
On this page
"The beginning is the most important part of the work." Plato 1. Install Brew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2. Update Ruby
brew install ruby
3. Install CocoaPods
First run sudo gem install cocoapods. If nothing happens, run gem sources --remove https://rubygems.org/. Wait until it responds, then enter gem sources -a http://ruby.taobao.org/. To verify that Taobao is your only Ruby mirror, use the following command:
gem sources -l
The command above has succeeded only when the following text appears in the terminal: ** CURRENT SOURCES **
http://ruby.taobao.org/
Now run sudo gem install cocoapods in Terminal again.
Wait a dozen or so seconds, then run pod setup.
4. Use the Search command to check whether the third-party library you need exists!
pod search SDWebImage
5. Create a Podfile
Use cd followed by the project path, then create the file.
touch Podfile
- Enter the following in the Podfile:
platform :ios, '7.0' pod "SDWebImage", "~> 2.0"
7. Finally, use esc :wq.
- Run
pod install.
To add another third-party framework through CocoaPods, run pod search followed by its name, add the latest version to the Podfile, and run pod install.
Pay attention to the last sentence: from now on, open the project with .xcworkspace rather than the previous .xcodeproj file.
Fixing missing autocomplete for third-party header imports when using CocoaPods
Open Target -> Build Settings and find \”User Header Search Paths\”. Add "${SRCROOT}" and select \”Recursive\” so Xcode searches the project directory recursively. Autocomplete should then work immediately.
You may wonder why an .xcworkspace file appeared. It was created by the $ pod install command you just ran. You will also find a new Podfile.lock file and a Pods folder.