Skip to content

Instantly share code, notes, and snippets.

@loganwright
Last active August 28, 2020 16:39
Show Gist options
  • Save loganwright/5aa9b3deb71e9de628ba to your computer and use it in GitHub Desktop.
Save loganwright/5aa9b3deb71e9de628ba to your computer and use it in GitHub Desktop.
Setting Up Cocoapods Guide

#Cocoapods

##Installing Cocoapods

  • Open Terminal
  • Enter command: sudo gem install cocoapods
  • Enter your password

Wait for this to finish, don't touch your terminal. It might take a couple minutes

  • Run command pod setup

##Setting Up Command Line Text Editor

#####Sublime

  • Download Sublime here
  • Install commandline tools following instructions here

#####Atom (My Preference)

  • Download Atom here
  • Install atom commandline tools by opening Atom and selecting Atom > Install Shell Commands

Continuing forward, all commandline references will use the atom keyword. Replace this with whatever you have designated as your text editor.

##Setting Up Cocoapods

###New Project

  • Create your Xcode Project
  • Make sure that Create git repository is selected

If you forgot to select this, just continue to the Existing Project section

###Existing Project

If your project is already setup with a git repository, skip this step.

  • Open terminal
  • Enter command cd ~/path/to/your/project
  • Enter command git init

###Setup Gitignore

  • Open terminal
  • Enter command cd ~/path/to/your/project (if necessary)
  • Enter command atom .gitignore
  • Add Pods/ to your gitignore
  • If your .gitignore is empty, add the following:
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
Pods/
  • Save your .gitignore file cmd + s

##Add Podfile

  • Open terminal
  • Enter command cd ~/path/to/your/project
  • Enter command atom Podfile

This is case SENSITIVE

###Source

Add a source to the top of your Podfile. If you're unsure what this should be, it should be this:

source 'https://github.com/CocoaPods/Specs.git'

###Platform

Specifying a platform is unncessary, but highly encouraged. The syntax is:

platform :<#platform#>, '<#version#>'

Example:

platform :ios, '7.0'

###Add Pods

You add pods to your project using the following syntax:

pod '<#pod name#>', '<#pod version'

A simple example would look like this:

pod 'AFNetworking', '1.0'

Or, to get the latest version, you can omit the version from the declaration:

pod 'AFNetworking'

There are more complex arguments regarding version available here

###Basic Podfile Example

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '7.1'

pod 'SVProgressHUD'
pod 'AFNetworking'

If you already have a workspace created, you'll need to specify this in your podfile by adding: workspace 'MyWorkspace'

##Installing Dependencies

Now we're going to integrate our libraries into the Xcode project.

  • Close Xcode Project
  • Open Terminal
  • Enter command cd ~/path/to/your/project
  • Enter command pod install

Wait for this to finish, depending on the requirements of the Podfile, particularly with new projects, this may take a minute or two. Just leave it.

When cocoapods is done installing libraries, you will get a terminal readout that says:

[!] From now on use <#Your Project#>.xcworkspace.

Follow this instruction and henceforth, use the workspace instead of your project.

##Importing And Using Libraries

Import cocoapod libraries like frameworks

#import <SomeCocoaPod/SomeCocoaPod.h>

##Advanced Podfile (in progress)

More on the Podfile: http://guides.cocoapods.org/using/the-podfile.html

###Pod Errors

Occasionally, imported libraries will have errors or warnings generated in Xcode, these can be silenced if desired by adding the following to the Podfile

inhibit_all_warnings!

To prevent warnings on a library specific basis, you can use the following syntax:

pod 'SomePodWithWarnings', :inhibit_warnings => true

@Raebel281
Copy link

I'm having trouble with the line: pod setup. It says that the 'command is not found' is there a way to fix this? (I'm incredibly new to this!)

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