Skip to content

Dependency management

Jan Mísař edited this page Aug 8, 2018 · 4 revisions

Now preferred way of dependency management is Carthage. Only dependencies which do not support it can be integrated using Cocoapods.

Carthage

At first I recommend the official Carthage README. This is just a basic tutorial for most common commands.

Generally Carthage uses two main files - Cartfile which holds list of dependencies (equal to Podfile in Cocoapods) and Cartfile.resolved which holds real versions that were installed (equal to Podfile.lock in Cocoapods)

Installing resolved versions

To install previously resolved versions of dependencies (all in Cartfile.resolved) run:

carthage bootstrap --platform iOS --cache-builds

This will install all dependencies in Cartfile.resolved and build them for the iOS platform.

NOTE: If you have added any dependency to Cartfile, it will not be installed as it is not yet in the Cartfile.resolved file, so it isn't equivalent to pod install command

Installing new dependency

If you're adding a new dependency - you want Carthage to add it to the Cartfile.resolved file, you should run:

carthage update --platform iOS --cache-builds <dependency_name>

If the dependency already existed it will be updated according to specified version in Cartfile. If the dependency_name argument is omitted, Carthage will install the newest versions of all dependencies according to Cartfile so be careful.

carthage update should be equivalent to calling pod update in Cocoapods.

Updating dependencies

This will update all dependecies from Cartfile (like if Cartfile.resolved never existed)

carthage update --platform iOS --cache-builds

Useful stuff for Carthage

I use some aliases for bash which simplify Carthage calls

alias cb='carthage bootstrap --platform iOS --cache-builds'
alias cu='carthage update --platform iOS --cache-builds'

For complete dependency management there is a lane cart which runs carthage bootstrap with some default parameters so you don't have to care really.

bundle exec fastlane cart

Cocopoads

If your dependency doesn't support Carthage or it doesn't make sense (SwiftGen, ACKLocalization, ...) just integrate it using Cocoapods.