Hoang Nguyen

CocoaPods, Carthage and SwiftPM. Choose it wisely in 2019

December 29, 2018 • ☕️ 3 min read

When we start with any platforms we will always ask “How can I integrate third party libs into my project?”. There is always a naive solution is copying the source manually into your project but you only use this in rare situations when you know what you’re doing

The best solution is to use a dependency manager. As an iOS developer, you have 2 options are CocoaPods and Carthage. SwiftPM included with Swift language but can’t be used with iOS for now

Cover

Version

  • Swift 4.2, iOS 12, Xcode 10
  • CocoaPods 1.5.3, Carthage 0.31.2, SwiftPM 4.2

CocoaPods

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. It has over 56 thousand libraries and is used in over 3 million apps. CocoaPods can help you scale your projects elegantly. CocoaPods is very easy to setup with Podfile and has a lot of libraries and plugins. The learning curve is low for any levels of app or framework developers

CocoaPods is centralized so all dependencies are stored in a central repository. It improves discoverability of, and engagement in, third party open-source libraries. It also supports own private code repository

CocoaPods does a lot of magic behind the scenes, it modifies project structure and configurations. You have to use Xcode workspace in order to make CocoaPods work. You will lose control over your Xcode project and must deal with Ruby

CocoaPods has a central point of failure is centralized repo. If you don’t commit pods along with your project and has no network or CocoaPods service is down, your project is dead to build and you just wait and cry

Carthage

Carthage builds your dependencies and provides you with binary frameworks, but you retain full control over your project structure and setup. Carthage does not automatically modify your project files or your build settings. Carthage has been created as a decentralized dependency manager. There is no central list of projects, which reduces maintenance work and avoids any central point of failure. However, project discovery is more difficult, users must discover libraries themselves on Github

Carthage won’t touch Xcode settings or Project files. Carthage is very simple and just check out and build the dependencies and leave it to you to add the binaries to Xcode. It gives you full control of what we are adding to Xcode. Carthage provide flexibility, easily integrated with Continuous Integration

Carthage involves a lot of manual setups to get started, the learning curve is high to setup so almost iOS developers are relectant to use it. It’s young and has small community, many frameworks are not available for Carthage especially older libraries that need to be added using git submodules

SwiftPM

The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies. It’s the new standard build by Apple to create Swift apps. Works in Linux. Currently doesn’t support all the platforms like iOS, watchOS, or tvOS

It Automatically manages a dependency’s dependencies. If a dependency relies on another dependency, Swift Package Manager will handle it for you

Mostly used for terminal app, backend app or library

My Favorite

I’ve been in iOS world for more than 6 years, I’ve been trying all these 3 tools in all kind of projects and teams. I’ve also been developing Javascript and loving npm package manager. So a centralized solution like CocoaPods is always my favorite

Conclusion

One thing is abundantly clear: there is no reason not to use a dependency manager in your iOS project. Which one should you chose? That depends on how much control you wish to exercise over your project’s structure and whether you are willing jump on the early adoption bandwagon

Don’t be afraid to use both CocoaPods and Carthage in the single project as it makes sense in many situations as mentioned above. We can take advantage of the features of both CocoaPods and Carthage at the same time


Hoang Nguyen

Senior Software Engineer
iOS, React Native