In my previous post about how to build features as frameworks, I discussed how you can improve your team’s productivity by using iOS frameworks directly in your project’s workspace. The example I walked through was quite simple and gave a starting point for this approach, but many of us need to build something more complex, which usually includes third party dependencies. It can be a bit tricky to integrate CocoaPods into your project when it is structured like this, so this is what I would like to explain in this tutorial.
CocoaPods or Carthage?
When deciding on a dependency manager for your iOS project, most people choose between two options: CocoaPods or Carthage. CocoaPods has been the standard bearer for many years now, and is a very mature codebase with tons of packages to choose from. The way it integrates code into your project is by creating a framework target for each of the included Pods, building the frameworks, and copying them into your main app module using a special script.
Carthage works a bit differently. It is not dependent on integration into your project, instead it downloads and builds the code for each dependency into their own frameworks that can then be imported into your project. This means dependencies must be integrated into your project manually, but it gives your project independence from Carthage itself.
What you choose as a package manager is up to you, and you can even use both if you need to. Carthage has the advantage of not rewriting any of your project file, while CocoaPods only takes a few automated steps to get you started. In this article, I will go over how to integrate CocoaPods into your internal frameworks.
Getting started with CocoaPods
Let’s begin with the small example project I wrote about in the previous article. I have made all the following changes on a branch in the repo called
use-cocoapods, but you can start with what’s already on the master branch. If you get stuck, check out the code to see the final result.