This post is just a reminder about how to use CocoaPods.
First things first...
What is CocoaPods
CocoaPods is a dependency manager for iOS projects.
It integrates third-party libraries into Xcode projects using a Podfile.
Install ruby
brew install ruby
Install CocoaPods
sudo gem install cocoapods
Verify the installation using
pod --version
Initialize CocoaPods in a project
First, go to the project folder (where .xcodeproj is located) and run
pod init
A minimal example of configuration
platform :ios, '15.0'
target 'YourAppTarget' do
use_frameworks!
pod 'Alamofire'
pod 'SnapKit'
end
Key things:
• platform → minimum iOS version
• target → must match your app target name exactly
• use_frameworks! → required for many Swift pods
Install the dependency
pod install
This creates:
• Pods/ folder
• YourProject.xcworkspace
🚨 From now on, open the .xcworkspace, not the .xcodeproj.
Using a pod in code
import Alamofire
AF.request("https://example.com").response { response in
print(response)
}
If it compiles → done.
Common commands
pod install # install dependencies
pod update # update dependencies
pod repo update # update specs repo
pod deintegrate # remove CocoaPods completely
pod search NAME # search pods
Typical problems & fixes
❌ “No such module”
• You opened .xcodeproj instead of .xcworkspace
• Target name mismatch in Podfile
❌ Build settings conflicts
pod deintegrate
pod install
❌ Slow installs
pod install --repo-update
Some additional notes
- CocoaPods is mostly for legacy projects
- For libraries that don't support SPM (Swift Package Manager)
- Consider using only Swift Package Manager
Top comments (0)