search by tags

for the user

adventures into the land of the command line

how to use cocoapods

I had absolutely no idea before. Now I kind of understand it’s like npm. The websites even look similar.

So first thing to do is install it. Open a terminal.

$ sudo gem install cocoapods
.
.
Installing ri documentation for ruby-macho-1.1.0
Parsing documentation for cocoapods-1.3.1
Installing ri documentation for cocoapods-1.3.1
27 gems installed

The pod utility has a number of features.

$ pod --version
1.3.1

$ pod
Usage:

    $ pod COMMAND

      CocoaPods, the Cocoa library package manager.

Commands:

    + cache         Manipulate the CocoaPods cache
    + deintegrate   Deintegrate CocoaPods from your project
    + env           Display pod environment
    + init          Generate a Podfile for the current directory
    + install       Install project dependencies according to versions from a
                    Podfile.lock
    + ipc           Inter-process communication
    + lib           Develop pods
    + list          List pods
    + outdated      Show outdated project dependencies
    + plugins       Show available CocoaPods plugins
    + repo          Manage spec-repositories
    + search        Search for pods
    + setup         Setup the CocoaPods environment
    + spec          Manage pod specs
    + trunk         Interact with the CocoaPods API (e.g. publishing new specs)
    + try           Try a Pod!
    + update        Update outdated project dependencies and create new Podfile.lock

Options:

    --silent        Show nothing
    --version       Show the version of the tool
    --verbose       Show more debugging information
    --no-ansi       Show output without ANSI codes
    --help          Show help banner of specified command

Let’s find a package to install, or a ‘pod’ as they call them. The first time you do it, it’s gonna do a massive git clone to somewhere on your computer, I don’t know where…

$ pod search sentry
Setting up CocoaPods master repo
  $ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
  Cloning into 'master'...
  remote: Counting objects: 1574476, done.        
  remote: Compressing objects: 100% (537/537), done.        
  remote: Total 1574476 (delta 278), reused 374 (delta 146), pack-reused 1573770        
  Receiving objects: 100% (1574476/1574476), 429.23 MiB | 2.76 MiB/s, done.
  Resolving deltas: 100% (830632/830632), done.
  Checking out files: 100% (186038/186038), done.
Setup completed
Creating search index for spec repo 'master'.. Done!

…and for this particular package, I got this message:

[!] Unable to find a pod with name, author, summary, or description matching `sentry`

Buuuuut when I did, it like this:

$ pod search sentry --simple

-> Sentry (3.8.2)
   Sentry client for cocoa
   pod 'Sentry', '~> 3.8.2'
   - Homepage: https://github.com/getsentry/sentry-cocoa
   - Source:   https://github.com/getsentry/sentry-cocoa.git
   - Versions: 3.8.2, 3.8.1, 3.8.0, 3.7.1, 3.7.0, 3.6.1, 3.6.0, 3.5.0, 3.4.3, 3.4.2, 3.4.1, 3.3.3, 3.3.2, 3.3.1, 3.3.0,
   3.2.1, 3.2.0, 3.1.3, 3.1.2, 3.1.1, 3.1.0, 3.0.12, 3.0.11, 3.0.10, 3.0.9, 3.0.8, 3.0.7, 3.0.6, 3.0.5, 3.0.4, 3.0.3,
   3.0.2, 3.0.1, 3.0.0, 2.1.11, 2.1.9, 2.1.8, 2.1.7, 2.1.6, 2.1.5, 2.1.4, 2.1.3, 2.1.2, 2.1.1, 2.1.0, 2.0.1, 2.0.0
   [master repo]
   - Subspecs:
     - Sentry/Core (3.8.2)
     - Sentry/KSCrash (3.8.2)

-> SentryKit (0.1.1)
   Swift client for sentry.io
   pod 'SentryKit', '~> 0.1.1'
   - Homepage: https://github.com/dcvz/SentryKit
   - Source:   https://github.com/dcvz/SentryKit.git
   - Versions: 0.1.1, 0.1.0 [master repo]

-> SentrySwift (1.4.5) [DEPRECATED in favor of Sentry]
   Swift client for Sentry
   pod 'SentrySwift', '~> 1.4.5'
   - Homepage: https://github.com/getsentry/sentry-swift
   - Source:   https://github.com/getsentry/sentry-swift.git
   - Versions: 1.4.5, 1.4.4, 1.4.3, 1.4.2, 1.4.1, 1.4.0, 1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.0, 1.1.0, 0.4.1, 0.4.0, 0.3.3,
   0.3.2, 0.3.1, 0.3.0, 0.2.2 [master repo]

-> MSSentryCocoaLumberjack (0.1.0)
   Custom CocoaLumberjack logger for Sentry
   pod 'MSSentryCocoaLumberjack', '~> 0.1.0'
   - Homepage: https://github.com/messeb/MSSentryCocoaLumberjack
   - Source:   https://github.com/messeb/MSSentryCocoaLumberjack.git
   - Versions: 0.1.0 [master repo]

Cool, let’s install one. Change to your project and create a podfile.

$ cd ~/xcode_projects/my_app/
$ pod init

This creates a 'Podfile’ in the current directory, which is not unlike a package.json in node or a requirements.txt file in python.

$ vim Podfile

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

    target 'my_app' do
      # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
      use_frameworks!

      # Pods for my_app
      pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '3.8.2'

      target 'my_appTests' do
        inherit! :search_paths
        # Pods for testing
      end

      target 'my_appUITests' do
        inherit! :search_paths
        # Pods for testing
      end

    end

Run the following command to install what you’ve added to the podfile.

$ pod install

Analyzing dependencies
Pre-downloading: `Sentry` from `https://github.com/getsentry/sentry-cocoa.git`, tag `3.8.2`
Downloading dependencies
Installing KSCrash (1.15.12)
Installing Sentry (3.8.2)
Generating Pods project
Integrating client project

This will create a new .xcworkspace file in the project directory. Use this one to run the project with the pods you have just installed, as the command line tells you:

[!] Please close any current Xcode sessions and use `Tanuki.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 2 total pods installed.

Done.