When working with a team of iOS developers, it can be useful to keep all team members on the same version of the pod
command (different versions of pod
can result in wildly different Xcode project files, resulting in a lot of noise in pull-requests).
One way to do this is to include a Gemfile
in your github repo, which specifies a specific version of Cocoapods:
$ cat Gemfile
source 'https://rubygems.org'
gem 'fastlane'
gem 'cocoapods', '1.4.0'
However, this means that team members must remember to run bundle exec pod
rather than pod
. This is both an annoyance and an easy mistake to make.
A solution to this is to use a pod
wrapper script which will run bundle exec pod
if it finds a Gemfile
, and otherwise use whatever pod
is in $PATH
.
This wrapper script can be checked in to your repo and symlinked into each developer's ~/bin
.
But how can a script named pod
execute the pod
command without instead calling itself in an endless loop?
There's a bit of trickery: the script removes its own $PATH
component before calling pod
!