CocoaPods and Carthage are the two main dependency managers for developing applications on iOS. But how do you decide if one of them is right for your project? We’ll go over what they are and how they work to give you the information you need to choose the right option for you.

At the highest level, choosing between them revolves around two major concepts:

  1. Centralization vs Decentralization
  2. Automated vs Configurable

Centralization vs decentralization

Centralization in a dependency manager means having a single source of truth for finding and downloading frameworks and libraries. Think NPM for JavaScript or RubyGems for Ruby, where all dependencies and their metadata reside in one place.

CocoaPods is centralized because it has a single repository on GitHub called Specs that stores every Pod’s Podspec. A Pod is a third-party library or framework that CocoaPods supports, and a Podspec is a file containing metadata about each Pod, including where to download the source code.

Pod::Spec.new do |s|
	s.name = 'Alamofire'
    s.version = '5.0.0-rc.3'
    s.license = 'MIT'
    s.summary = 'Elegant HTTP Networking in Swift'
    s.homepage = 'https://github.com/Alamofire/Alamofire'
    s.authors = { 'Alamofire Software Foundation' => 'info@alamofire.org' }
    s.source = { :git => 'https://github.com/Alamofire/Alamofire.git', :tag => s.version }
    s.documentation_url = 'https://alamofire.github.io/Alamofire/'
    
    s.ios.deployment_target = '10.0'
    s.osx.deployment_target = '10.12'
    s.tvos.deployment_target = '10.0'
    s.watchos.deployment_target = '3.0'
    
    s.swift_versions = ['5.0', '5.1']
    
    s.source_files = 'Source/*.swift'
    
    s.frameworks = 'CFNetwork'
end
Alamofire Podspec

When a developer wants to check if a library or framework is supported by CocoaPods, all they have to do is search the CocoaPods website. This makes it easier to developers to find dependencies.

Conversely, Carthage is decentralized because there is no single repository for finding dependencies. A problem with this approach is discoverability. A developer might not use a helpful dependency simply because they couldn’t find it or didn’t know about it.

Automated vs configurable

When considering a dependency manager, it’s important to note the level of configuration you wish to have. In many use cases, having an automated dependency manager frees up time that would otherwise be spent on boilerplate integration. In other situations, a developer might prefer a more custom setup. For example, a developer who wants to individually decide how to link frameworks (statically versus dynamically) cannot rely on an automated integration solution.

CocoaPods is an automated solution.  To include a Pod in their project, a developer simply needs to add it to their Podfile.

platform :ios, '10.0'
source 'https://github.com/CocoaPods/Specs.git'
target 'yourProjectName' do
  use_frameworks!

pod 'Alamofire', '~> 4.5'
end
Example Podfile For Alamofire

When a developer runs the command pod install, CocoaPods automatically does a few things:

  1. Creates a new Xcode workspace. The developer must edit their application from this new workspace instead of the original project folder.
  2. Adds a Podfile.lock file that specifies the versions of the dependencies.
  3. Adds scripts to the build phases of the target.
  4. Links the frameworks to “Link Binaries With Libraries”.
  5. Creates a Pods directory that stores the source code of the dependencies, supporting files, and xconfig files.

CocoaPods creates a specific project structure. It adds framework/library linking. It attaches post-build scripts. This is all done automatically, so the developer doesn’t have to worry about it.

Carthage on the other hand is highly configurable. It downloads and builds binary frameworks. Everything else is left to the developer. Examples include setting up framework/library linking and adding post-build scripts. It’s certainly more time-consuming, but with Carthage, you control exactly how your dependencies are incorporated into your project.

However, if you opt for CocoaPods’ more automated solution, you’re committing to the amount of control it enforces on your project. Removing CocoaPods from your project is more difficult than from Carthage.

Which one do I pick?

You’ll probably hate us for this answer, but it’s completely up to you! CocoaPods is a“set it and forget it” type of setup. Carthage is more of a“get your hands dirty” type. It all depends on how you value centralization and configurability.

But at the end of the day, the best dependency manager is whichever one helps you be more productive.

Here at Embrace, we don’t want you to have to worry about anything other than choosing the dependency manager you are most happy with, so we offer support for both CocoaPods and Carthage. If you’d like to learn more about how to use either option, you can check out our docs for CocoaPods here and for Carthage here!