BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

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

Carthage: GitHub's Dependency Manager for Xcode Projects

Leia em Português

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

BT