Skip to content

Instantly share code, notes, and snippets.

@galileoguzman
Last active January 27, 2016 19:25
Show Gist options
  • Save galileoguzman/d83a7983d4d54a0ff58a to your computer and use it in GitHub Desktop.
Save galileoguzman/d83a7983d4d54a0ff58a to your computer and use it in GitHub Desktop.
Tutorial Cocoapods

How to use Cocoapods with ObjC

This file will help you to init project with Xcode and Objective C with pagage manager Cocoapods. The head first are make sure that we have installed Cocoapods on our system.

IMPORTANT: Make sure you have ruby cli installed on your system.

sudo gem install cocoapods

After have installed cocoapods, you have to export the environment vars for your system can to recognize cocoapods cli.

export GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH

Hands on work

  1. Now you need create a new Xcode Project with ObjC, choose the location of your project and make sure mark the Git initialization option is selected.

  2. Close Xcode.

  3. Open your favorite terminal (My Favorite terminal is iTerm with "oh my zsh" plugin).

  4. Go to the folder project from your terminal with command "cd your/folder/proect/directory".

  5. Now you have to create the famously "Podfile":

     touch Podfile
    
  6. After that command, if you list the content directory you'll can see file with name Podfile. Now it's time to run the next command.

     pod install
    

Output

    CocoaPods 1.0.0.beta.2 is available.
    To update use: `gem install cocoapods --pre`
    [!] This is a test version we'd love you to try.
    
    For more information see http://blog.cocoapods.org
    and the CHANGELOG for this version http://git.io/BaH8pQ.
    
    Analyzing dependencies
    Downloading dependencies
    Generating Pods project
    Integrating client project
    
    [!] Please close any current Xcode sessions and use `NameProject.xcworkspace` for this project from now on.
    Sending stats
    Sending stats
    Sending stats
    Pod installation complete! There are 0 dependencies from the Podfile and 0 total
    pods installed.
    
    [!] [!] The Podfile does not contain any dependencies.

7.- The last command is in charge of create project the dependencies and new Workspace to work on Xcode.

    `NameProject.xcworkspace`
  1. Now you can open the new Workspace from the terminal with the next command, or open the from Finder app.

     open NameProject.xcworkspace
    

Adding dependencies

Now, you can add dependency libs to project. You need add some lines to Podfile like the next sample:

    platform :ios, '9.0'
    inhibit_all_warnings!
    
    target "NameProject" do
    
      pod 'ObjectiveSugar', '~> 0.5'
    
    end
    
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        puts "#{target.name}"
      end
    end

Now you can run for download and install dependencies

    pod install

Enjoy it!!!

@galileoguzman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment