CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. Its used in just about every iOS project here at Intrepid.
Here is how to set it up.
- 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
- 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.
- 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
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
- 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
- Open terminal
- Enter command
cd ~/path/to/your/project
- Enter command
atom Podfile
This is case SENSITIVE
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'
Specifying a platform is unncessary, but highly encouraged. The syntax is:
platform :<#platform#>, '<#version#>'
Example:
platform :ios, '7.0'
- Open terminal
- Enter command
pod init
- Uncomment the platform line to specify a platform (ex.
platform :ios, '8.0'
)
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
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
target 'ProjectName' do
pod 'SVProgressHUD'
pod 'AFNetworking'
end
If you already have a workspace created, you'll need to specify this in your podfile by adding:
workspace 'MyWorkspace'
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.
In your project, if you want to use a library you can do so by adding
import SomeCocoaPod
More on the Podfile: http://guides.cocoapods.org/using/the-podfile.html
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
- These notes are just slightly modified from Logan's https://gist.github.com/LoganWright/5aa9b3deb71e9de628ba
- The dank grape gif is a masterpiece that belongs to FoxADHD