DEV Community

Cover image for [iOS] CocoaPods cheatsheet
Armando Picón
Armando Picón

Posted on

[iOS] CocoaPods cheatsheet

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
Enter fullscreen mode Exit fullscreen mode

Install CocoaPods

sudo gem install cocoapods
Enter fullscreen mode Exit fullscreen mode

Verify the installation using

pod --version
Enter fullscreen mode Exit fullscreen mode

Initialize CocoaPods in a project

First, go to the project folder (where .xcodeproj is located) and run

pod init
Enter fullscreen mode Exit fullscreen mode

A minimal example of configuration

platform :ios, '15.0'

target 'YourAppTarget' do
  use_frameworks!

  pod 'Alamofire'
  pod 'SnapKit'
end
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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)
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Typical problems & fixes

❌ “No such module”
• You opened .xcodeproj instead of .xcworkspace
• Target name mismatch in Podfile

❌ Build settings conflicts

pod deintegrate
pod install
Enter fullscreen mode Exit fullscreen mode

❌ Slow installs

pod install --repo-update
Enter fullscreen mode Exit fullscreen mode

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)