Thanks to the
Podfile.lock every machine which runs pod install on the
hypothetical project will use RestKit 0.10.3 even if a newer version is
available. CocoaPods will honour this version unless the dependency is updated
on the Podfile or
pod update is called. In this way CocoaPods avoids headaches
caused by unexpected changes to dependencies.
This file should always be kept under version control.
What is happening behind the scenes?
In Xcode, with references directly from the ruby source, it:
- Creates or updates a workspace.
Adds your project to the workspace if needed.
- Adds the CocoaPods static library project to the workspace if needed.
- Adds libPods.a to: targets => build phases => link with libraries.
- Adds the CocoaPods Xcode configuration file to your app’s project.
- Changes your app's target configurations to be based on CocoaPods's.
- Adds a build phase to copy resources from any pods you installed to your app bundle. i.e. a ‘Script build phase’ after all other build phases with the following:
Note that steps 3 onwards are skipped if the CocoaPods static library is already in your project. This is largely based on Jonah Williams' work on Static Libraries.
Pods and Submodules
CocoaPods and git submodules attempt to solve very similar problems. Both strive to simplify the process of including 3rd party code in your project. Submodules link to a specific commit of that project, while a CocoaPod is tied to a versioned developer release.
Switching from submodules to CocoaPods
Before you decide to make the full switch to CocoaPods, make sure that the libraries you are currently using are all available. It is also a good idea to record the versions of the libraries you are currently using, so that you can setup CocoaPods to use the same ones. It's also a good idea to do this incrementally, going dependency by dependency instead of one big move.
- Install CocoaPods, if you have not done so already
- Create your Podfile
- Remove the submodule reference
- Add a reference to the removed library in your Podfile