BT

Carthage: GitHub's Dependency Manager for Xcode Projects

| by Sergio De Simone Follow 13 Followers on Apr 28, 2015. Estimated reading time: 1 minute |

Carthage is a dependency manager for Objective-C and Swift projects aims to be "ruthlessy simple," says its author Justin Spahr-Summers. Carthage has been developed at GitHub and its philosophy is "delegating tasks to Xcode and Git" as much as possible so developers can use the tools they "are already familiar with."

Dependency management is key in order to be able to effectively reuse code through libraries or frameworks. As Spahr-Summers recounts, before Carthage several ways to distribute libraries were available for Cocoa/CocoaTouch projects:

  • Manually copied source files, which does not support any kind of versioning and thus is prone to conflits.
  • Subversion externals, Git submodules, or Git subtrees, each of which has its own flaws, says Spahr-Summers. In particular, Git submodules tend to work pretty well until two or more of your project's dependencies have a common dependency.
  • CocoaPods, the de-facto standard for dependency management with Cocoa. Unfortunately, CocoaPods has a few drawbacks, according to Spahr-Summers, such as the requirement to add a Pod specs file to all projects and to upload it to a central repository. The biggest CocoaPods' drawback, though, is how it takes "control of the project set up process," by creating an Xcode workspace for you and adding its Pod projects to it.

Thus, Carthage was born with the goal of being "a simple coordinator between Git and XCode" that would "pick compatible versions for all dependencies, check out dependencies with Git, and then build frameworks with Xcode."

Using Carthage requires the developer to carry through a series of steps:

  1. The first step in order to be able to use Carthage is to install it, either through a prepackaged binary installer, or using Homebrew. This step is only required once.

  2. Then, all required GitHub dependencies can be specified in a Cartfile, e.g.

    github "Mantle/Mantle" ~> 1.5
    github "ReactiveCocoa/ReactiveCocoa" >= 2.4.7
    github "ReactiveCocoa/ReactiveCocoaLayout" == 0.5.2
    
  3. Once the Cart file has been created, running carthage update will recursively download and build all dependencies.

  4. Finally, all frameworks that Carthage built can be added to an Xcode project. For iOS, an additional required step is to strip architectures since the App Store does not allow framework binaries that include X86_64 binaries.

One limitation of Carthage comes from it only supporting frameworks, so it is not possible to use it for apps targeting iOS version prior to iOS 8.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT