cocoapods Getting started with cocoapods

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


Cocoapods is a dependency manager for Swift and Objective C projects. As stated from the official site, it has over 28 thousand libraries and is used in over 1.7 million apps. It can make developers develop faster by using third party libraries. Cocoapods makes managing dependencies in your code easier. Adding and removing dependencies can be done by writing them in a file (called the podfile) and running it.


Getting Started

Lets start installing the popular library Alamofire to our Xcode project!

Lets first install CocoaPods by using the command:

[sudo] gem install cocoapods

Then let's create a new project in Xcode called Start! Navigate to the folder that contains the .xcodeproj and create a new text file called podfile !

Replace the podfile with the following:

source ''
platform :ios, '10.0'

target 'start' do
    pod 'Alamofire', '~> 4.3'

Use the cd command to change to the directory containing the .xcodeproj and issue the command pod install . Alamofire is installed in the project 'start'!

Now, double-click the xcworkspace file (not .xcodeproj) and use Alamofire!

Podfile sample

The dependencies for your projects are specified in a single text file called a Podfile. CocoaPods will resolve dependencies between libraries, fetch the resulting source code, then link it together in an Xcode workspace to build your project.

  1. Create a podfile

    # Next line contains target platform settings
    platform :ios, '8.0'
    # Use dynamic Frameworks
    # Target name
    target 'MyApp' do
      # List of target dependencies
      pod 'ObjectiveSugar', '~> 1.1'
      pod 'ORStackView', '~> 3.0'
      pod 'RxSwift', '~> 2.6'
  2. Install dependencies. The process of dependencies installation is done by executing this command through terminal in the project directory:

    pod install
  3. Updating dependencies to new versions:

  • Updating specific pod

    pod update RxSwift
  • Updating all pods

    pod update

Using Cocoapods

Updating CocoaPods

To update CocoaPods by simply installing the gem again

[sudo] gem install cocoapods

Or for a pre-release version

[sudo] gem install cocoapods --pre

Got any cocoapods Question?