🥥CocoaPods

Fall 2023 | Vin Bui

What is CocoaPods?

CocoaPods is a dependency manager for Swift and Objective-C projects in Xcode. It is used in over 3 million apps and contains over 95 thousand libraries. It is similar to pip for Python and npm for NodeJS. In other words, you can use code written by other people in your own Xcode project to make your life easier!

CocoaPods Setup

  1. To install CocoaPods, simply run the following in the command line: sudo gem install cocoapods

  2. Navigate to your Xcode project directory and run this command: pod init. This creates a Podfile in your directory.

  3. Open the Podfile and list out the pods you want to install. For example, if I wanted to install the latest version of SnapKit and Alamofire, my Podfile would look something like this:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'MyApp' do
  use_frameworks!

  # Pods for MyApp

  pod 'SnapKit'
  pod 'Alamofire'
end

Change ‘MyApp’ to the name of your project.

  1. Once you are done, save your Podfile and install the dependencies by running pod install

    • If this command does not work, try pod install --repo-update

You must open the Xcode workspace instead of the project when using CocoaPods!

Last updated