Dependency Managers: CocoaPods, Carthage and Swift Package Manager

Profile Picture of Andres Canal
Andres Canal
Senior Full-stack Mobile Developer
Diagram of dependencies in an application

These days, developers that write all their own code are rare, and with good reason. Why reinvent the wheel when you can find well written, and well supported, third-party libraries that will help build products faster?

Inserting other people’s code into your project does throw up some issues, including the need to effectively manage all of these various libraries. A role commonly filled by dependency managers.

Table Of Contents

What Is a Dependency Manager?

A dependency manager is simply a tool that helps you integrate external libraries into your project. Usually, they include a list that states what libraries and versions are available and how to grab them. Once the dependency manager knows all of this, it takes care of fetching the correct versions and integrating that into your project (or leaving the libraries ready to be integrated by you at a later date).

iOS dependency managers

In this article, I will focus on dependency manager tools used within the Apple environment: Carthage, CocoaPods, and Swift Package Manager.

This post is not a beginner’s guide to dependency managers, it is instead a cross-reference so developers can easily learn to switch between Carthage and CocoaPods. For example, let’s suppose you have worked extensively with CocoaPods, but suddenly find yourself on a new project that uses Carthage. You don’t need to learn what Carthage is – you just need to learn how to perform the actions you previously did in Cocoapods, but on Carthage. 

This article will facilitate this, increasingly common, transition. I’ve also sketched out an introduction to the newer Swift Package Manager to highlight its current use cases and weaknesses.

CocoaPods for Carthage Users

Originally published on Jul 30, 2018Last updated on Jan 17, 2024

Key Takeaways

What is the difference between Swift Package Manager and CocoaPods?

To highlight some distinctions, Swift Package Manager is a decentralized dependency manager, while CocoaPods is centralized. Notably, CocoaPods can only be run on macOS, while Swift Package Manager is compatible with both macOS and Linux. Another important distinction worth mentioning is that Swift Package Manager is written in Swift, whereas CocoaPods is developed using Ruby.

Can I use Swift Package Manager with CocoaPods?

Yes, you can use Swift Package Manager with CocoaPods. CocoaPods is commonly employed to manage dependencies in iOS and macOS projects, as its unique approach helps to organize and integrate libraries into Xcode projects. On the other hand, Swift Package Manager is crafted as a native dependency manager specifically for Swift projects, providing a more seamless integration within the Swift ecosystem.

Is CocoaPods still used in 2023?

Yes, CocoaPods is still being used in 2023. CocoaPods provides a dedicated space to store metadata for all available libraries, which enables you to adopt a centralized approach and simplifies library searches. What’s more, CocoaPods is sponsored by major companies like Capital One, contributing to its continued popularity as a preferred dependency manager.

Is CocoaPods better than SPM?

SPM was lacking in features when it first came up, but it quickly caught up with CocoaPods and Carthage. Nowadays, being the Swift native option, SPM is a reliable choice as a package manager. If you have a legacy project that works with CocoaPods or Carthage, there is no reason not to stick to these tools. However, if you are starting a new project, Swift Package Manager would be the way to go.