[iOS] CocoaPods cheatsheet
Source: Dev.to
Introduction
CocoaPods is a dependency manager for iOS projects.
Installation
brew install ruby
sudo gem install cocoapods
Verify the installation:
pod --version
Initialising a Podfile
Navigate to the folder containing your .xcodeproj and run:
pod init
Edit the generated Podfile (Ruby DSL) to specify the platform, target, and desired pods:
platform :ios, '15.0'
target 'YourAppTarget' do
use_frameworks!
pod 'Alamofire'
pod 'SnapKit'
end
Installing Pods
pod install
🚨 From now on, open the
.xcworkspacefile, not the.xcodeproj.
Example usage
import Alamofire
AF.request("https://example.com").response { response in
print(response)
}
If the code compiles, you’re all set.
Common CocoaPods Commands
| Command | Description |
|---|---|
pod install | Install the dependencies listed in the Podfile. |
pod update | Update the installed dependencies to the latest compatible versions. |
pod repo update | Refresh the local specs repository. |
pod deintegrate | Remove CocoaPods from the project completely. |
pod search NAME | Search for a pod by name. |
Troubleshooting
-
“No such module” or Build settings conflicts
pod deintegrate pod install -
Slow installs
pod install --repo-update
When to Use CocoaPods
- Legacy projects that already rely on CocoaPods.
- Libraries that do not yet support Swift Package Manager (SPM).
For newer projects, consider using Swift Package Manager instead.