Dependency management strategy with Carthage

Riad Krim
2 min readFeb 12, 2018

--

Photo of Richard Mortel distributed under Creative Commons license CC BY-NC-SA.

While discussing with iOS and macOS developers, I realised that they almost all know Carthage, but unfortunately, some of developers think that its only limited to a carthage update command to download frameworks.

If you only know update as option, or if you tend to use only this one, you’ll find in this article, a simple but efficient dependency management strategy based only on two Carthage options, update and bootstrap.

Carthage usage basics

Carthage workflow is based on a Cartfile that is the interface between the developer and the tool. We add in this file all the frameworks that we want in an OGDL format. To simplify, we write one framework per line by adding its origin (Git repo, github or binary) and optionally the version to download.
Note: Other necessary steps are required the first time adding every framework (see: Adding frameworks to an application).

carthage update

This command will download all frameworks listed in Cartfile by resolving all dependencies ; build them (if no version requirement was indicated, the last version of the dependency is downloaded) and update the resolution file carthage.resolved by listing all dependencies (even nested ones) with the exact version of each one that was chosen for download.

carthage bootstrap

This command will download and build frameworks exactly as they figure in carthage.resolved file. If the file (carthage.resolved) does not exist, this command will execute an update, that will resolve the dependencies and (re)generate it.

Strategy

It consist, at first, of adding Cartfile and carthage.resolved to the version control system (Git for most) and excluding Carthage directory and its sub directories to keep the repo lightweight.

Then, all team members need to use carthage bootstrap every time they need to get the needed frameworks (when switching to a new branch that doesn’t contain same framework version, or a branch that does contain a new framework, for example).

Finally, use carthage update only when you really need to update frameworks and add those 2 files to your commit (after testing and/or adapting implementation for the changes, of course).

General
It’s possible to apply the same strategy to other dependency management tools, like:
Cocoapods, with pod install, pod update and both Podfile and Podfile.lock
Bundler, with bundle install, bundle update and both Gemfile and Gemfile.lock
And probably to other tools of the same kind.

Other versions of this article: French
Github Project: Carthage

--

--