cocoapods

Getting started with cocoapods

Remarks#

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.

Versions#

VersionRelease NotesRelease Date
1.2.0https://github.com/CocoaPods/CocoaPods/blob/master/CHANGELOG.md#120-2017-01-282017-01-28
1.1.1https://github.com/CocoaPods/CocoaPods/blob/master/CHANGELOG.md#111-2016-10-202016-10-20
1.1.0https://github.com/CocoaPods/CocoaPods/blob/master/CHANGELOG.md#110-2016-10-192016-10-19
1.0.1https://github.com/CocoaPods/CocoaPods/blob/master/CHANGELOG.md#101-2016-06-022016-06-02
1.0.0https://github.com/CocoaPods/CocoaPods/blob/master/CHANGELOG.md#100-2016-05-102016-05-10

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

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
    use_frameworks!
    
    # Target name
    target 'MyApp' do
      # List of target dependencies
      pod 'ObjectiveSugar', '~> 1.1'
      pod 'ORStackView', '~> 3.0'
      pod 'RxSwift', '~> 2.6'
    end
  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

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 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

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

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!


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow