Ok, we all are smart developers and do not drag and drop dependencies in our iOS Xcode project and use CocoaPods instead, right? Good. But on occasion you struggle with teammates' or your own CocoaPods version desynchronization or similar issues, am I correct?
Ok, great, than you're about to see a bulletproof CocoaPods setup we use on all of our projects. We distilled the best through try and failure.
Ultimately we want to have CocoaPods set up just right for every member of the team. But if you think of it CocoaPods is a Ruby gem and could potentially have different versions installed on different machines (hence
pod install issues after pulling the latest code from master, etc.) so you'd want to have it in sync as well. Also potentially your teammates could have different Ruby versions installed which also could be a problem (they can't install the right cocoapods gem version or already have an outdated one, etc.). To solve these problems we need to move from the bottom in 3 steps:
Step 1. RVM for Ruby.
We need RVM to help us manage Ruby versions and have everyone on the team have a clean isolated gemset where CocoaPods gem will reside.
- install rvm https://rvm.io/rvm/install
cdto your project directory and create an rvmrc:
rvm --rvmrc --create ruby-v.e.r.s.i.o.n@project_name
If you did everything correct every time you and/or your teammates
cd into the project directory RVM will switch to the right version of Ruby and the right gemset that contains CocoaPods gem.
Step 2. Bundler for CocoaPods gem.
Next you need to install Bundler to manage CocoaPods gem versioning.
gem install bundler should do the trick. Then create a
Gemfile in the root of your project and type in:
source 'https://rubygems.org' gem 'cocoapods', '~> 0.34.0'
And after that
This will put all of your team on the same page in regards of CocoaPods gem version.
Step 3. CocoaPods for Xcode project.
And the last step is to setup CocoaPods itself for your iOS project.
By now it should be as simple as simple as:
- create a
- put something like this in:
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' pod 'AFNetworking', '~> 2.0' pod 'ARAnalytics', '~> 2.7'
That's it. Now you have bulletproof setup for keeping everyone on the team on the same page in regards of CocoaPods themselves, CocoaPods gem version, and Ruby version.
Oh, and one last tip - don't forget to put
If you have any questions about CocoaPods, Bundler, or RVM feel free to leave a comment below or shoot us an email at email@example.com, we'd be happy to help you.
Alex Bush @alexvbush