This question is about how to get the latest code for CocoaPods-managed dependencies during development, i.e. without doing the whole "push a new podspec" dance.
Setup
Say we have three projects A
, B
, and C
. The dependencies are such that A
depends on B
, and B
depends on C
. Each project resides in its own Git repository.
We figured we'd use a dummy minor version to identify the current state of the code. The podspecs reside in our own repository.
# A/Podfile
...
pod 'B', '1.dev'
# B/Podfile
...
pod 'C', '1.dev'
# B/B.podspec
Pod::Spec.new do |s|
s.name = 'B'
s.version = '1.dev'
...
s.dependency = 'C', '1.dev'
end
# C/C.podspec
Pod::Spec.new do |s|
s.name = 'C'
s.version = '1.dev'
...
end
The Problem
We push a new commit to (the master branch of) C
. We expect
A$ pod update
to retrieve the change. This does not happen.
Approaches
Whenever we (know to) want to pull the dependencies anew, do:
A$ rm -rf Pods/ Podfile.lock A$ pod cache clean --all A$ pod install
This definitely gets the latest code. However, it's a sledgehammer that's neither convenient nor efficient to do after every pull in
A
, push in eitherB
orC
, or switching between branches inA
.In order to stick close to the setup, we'd have to create a whole new set of podspecs and Podfiles after every (meaningful) set of commits on a master branch (i.e. a merge of a feature branch), all with a new version
1.x-y
(y
a build number or something); push the podspecs; and runpod update
inA
andB
.While this may be feasible in a CI setup (which we unfortunately don't have, yet), it's prohibitive work to do manually. Git hooks may be a workaround.
On non-version branches, do
# A/Podfile ... pod 'A', :git => "...", :branch => "master"
That is, circumvent the podspec repo. Unfortunately, this won't work here becaus
pod
will inspectB.podspec
and find its dependencyC
, which we can not specify in a similar way. Also,pod update
always re-installs, no matter if there were new commits.
Question
Is there a good (low maintenance) way to track branches with CocoaPods? If not, what are alternatives?
A possible solution is to use local pods.
Architecture for sample:
This way in your PodFile A, you do:
This add the possibility to modify yourself the classes of your pod without asking for a
pod update
/git pull and also not prompting the “MyFileInMyPod” is locked for editing and you may not be able to save your changes. Do you want to unlock it? from XCode each time.How do we tell everyone to do so, meaning keeping the architecture of folders?
Using Repo, tool by Google!
What is this tool in a few lines:
It can pull from various git repositories at the same times keeping a synchronized work.
You have a
manifest.xml
files where you specify the repositories, the branches, and the local path (for the local architecture). Here is a tutorial. If you are using private repositories, I'd suggest using an HostAlias with SSH Keys.My coworker continues to use Repo, I don't really. I keep pulling/pushing each one of them one by one using SourceTree.app, I used Repo only for the "starter" and that created me my whole local architecture.
In our own project:
I, most of the time, work on MainApp, and need to modify CoreClasses without any issue this way.
Sample of our Manifest.xml (in another private repository where there is almost only file):