BT

InfoQ Homepage News Carthage: GitHub's Dependency Manager for Xcode Projects

Carthage: GitHub's Dependency Manager for Xcode Projects

Leia em português

This item in chinese

Bookmarks

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
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.

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

Community comments

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

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

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.