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:
- Centralization vs Decentralization
- Automated vs Configurable
Centralization vs Decentralization
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.
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.
When a developer runs the command pod install, CocoaPods automatically does a few things:
- Creates a new Xcode workspace. The developer must edit their application from this new workspace instead of the original project folder.
- Adds a
Podfile.lockfile that specifies the versions of the dependencies.
- Adds scripts to the build phases of the target.
- Links the frameworks to “Link Binaries With Libraries”.
- Creates a Pods directory that stores the source code of the dependencies, supporting files, and
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!