Carthage vs. CocoaPods
A couple of thoughts on Carthage compared to CocoaPods.
What Carthage has in common with CocoaPods:
- You create a Podfile for CocoaPods. For Carthage, you need to create a Cartfile.
- In both cases, you can specify an exact dependency version and a specific git repository.
- After installing dependencies, CocoaPods creates Podfile.lock and Carthage creates Cartfile.resolved so that exact dependency/library versions can be installed.
- Both CocoaPods and Carthage are quite easy to install with a single console command.
Cons:
- All dependencies have to be added manually to the project and the Build Phases section. You only do it once, but it is still manual, unlike CocoaPods, which generates the workspace on its own. On the one hand this is inconvenient, on the other, CocoaPods has simply spoiled us. For example, in the Node.js world it is not enough to do npm install package, you still have to include the dependency where needed via require.
- Less choice. Less popularity. CocoaPods is older, more popular, and many libraries were distributed through CocoaPods. Many are still distributed only through it, including, for example, SDKs from Google. With Carthage it is easier to find something relatively fresh. On the plus side, it is usually available via CocoaPods, Carthage, and even Swift Package Manager.
Pros:
- Dependencies are built once. On any project build, the libraries and dependencies are not rebuilt, even if you clear all caches and do all the cleans. As a result, every build is faster.
- No extra .xcworkspace file is created, and the project file remains untouched. Workspace creation in recent CocoaPods versions has been buggy for almost half a year already and creates that workspace in a way that makes the project fail to build, so you have to go in manually and fix something. For example, the header search path.
- When updating a dependency to the latest version, again, the project file is not touched. The dependencies are simply rebuilt; they are already added to the project.
- You can build a dependency for all platforms at once, or for a specific one, for example tvOS.
- CocoaPods has a central repository. If it goes down, nothing will work. Carthage does not have that; it just pulls dependencies from GitHub. On the one hand that is still a kind of central repository, but without the middle layer, and the chances of it withstanding load are higher.