When To Use Cocoapods? When To Use Carthage?
Do I need to use Cocoapods only or Carthage only or use both?
Every mobile app developer in the world must have used package manager. While in Android, we have an official package manager using Gradle but in iOS there’s still no official until recently Apple announced Swift Package Manager. But the majority of iOS devs are still using Cocoapods and some of them using Carthage. * In my opinion, package manager needs to be small, feels like scripting a.k.a fast to write and is easy to read. It doesn’t need a verbosity & many features of a programming language. That’s why Swift Package Manager still has a low adoption rate.
Some of the iOS dev might be confused on whether they need to use Cocoapod / Carthage, but in reality, you can use both and leverage each their advantages.
Let’s look at Cocoapods first. Cocoapod will build / compile your pods (library) after you hit Build everytime after you’ve done running pod install
/ pod update
/ after Clean project. Consecutive Build will not rebuild your pods.
Carthage takes a different path. When you retrieve your library using carthage update
it will either retrieve the framework (binary) version or pull the source and compile it into framework (on your machine) and this process happens only once. So XCode will not rebuild anything if you’re using Carthage.
So if you want to use library with large codebase, use Carthage to integrate it into your project. But, how do I know if a library has large source code? If you add the lib via Cocoapods and when you build your project, you saw something like this and took a long time to finish :
Then, this is a sign that you should use Carthage to integrate that library. If you want to just try a library or a small library or a library that only support Cocoapods, then use Cocoapods. If you’re using many libraries in Cocoapods and some of the libs will be there to stay and you don’t need to update them, you can consider to move that lib(s) integration to Carthage instead.
Some of the libraries have subspec, which is an additional functionality that is optional to use. As long as I know, this feature only available for Cocoapods, while in Carthage you will need to add whole features.
So, don’t be afraid to use both (ps. it won’t break your project) and leverage their greatness. Thank you for reading.