Carthage update: Using Carthage to resolve your dependencies

In this lesson

This lesson will show you how to use the Carthage update command to fetch and checkout the appropriate version of each of our dependencies. I will show you some of the optional flags you can pass to this command to refine how Carthage update runs.


Tap on time to skip ahead


We’re finally ready to use Carthage to resolve our dependencies. As a reminder, this is my Cartfile where I have expressed all of the frameworks that I want to use as dependencies in the new app that I’m building and the version requirements.


Let’s head over to the terminal window. I’m going to show you, if you type carthage help, it will print out a list of the commands that you can give to Carthage. The one we’re interested in right now is called update. I’m going to call carthage update and I’m going to say, “–use-ssh,” which is a command line option for the update command. It’s going to use SSH to communication with GitHub to resolve my dependencies.


I’m going to also pass a –no-build parameter to the update. What that’s going to do is just go resolve all my dependencies. This takes a couple of seconds depending on how many dependencies you have defined. One thing you’ll notice is that there are more dependencies being listed here than I declared in my Cartfile. Let’s take a look at why that is.


If we compare our Cartfile that contains six dependency declarations to what Carthage actually resolved, which is 11 different dependencies, there’s a disconnect here. Why did it resolve 11 when I only declared six? That’s because Carthage resolves the entire dependency graph.


How does Carthage determine this? Well, if we have a look at one of the dependencies, one of mine, which is the lol-datadragon-content-provider. I go look at the GitHub repo for that, if we look at the code in this, you’ll see that it has its own Cartfile. If I click on that, you’ll notice that there are additional dependencies declared here. There’s one on swift-content-provider, one on swift-protocols-sqlite and also Alamofire. What happens is, Carthage will recursively, step through all of your dependencies declared in your own Cartfile and look for Cartfiles in all of those, and continue that until all of the dependencies have been resolved. In this case, Carthage examined all of the dependencies I declared in my Cartfile. It found Cartfiles in some of those dependencies and resolved those recursively. What we ended up with here is 11 total dependencies for this application.


What’s this down here? After it fetched everything, or cloned each of those GitHub repositories, we see that GitHub reported that it was checking out specific versions of each of those. What that really does is it issues a Git checkout against the version that I’ve specified in my Cartfile or in the Cartfiles of any of my dependencies so that we are ready to go.


To see what actually happened when I ran Carthage update, let’s use Finder. Here’s my NewApp folder. You’ll notice that it created a file and another folder. We’re going to ignore the Cartfile.resolved for now but look at the Carthage folder. Inside that there’s a Checkouts folder. If we open that, you’ll see that it actually created folders for each of the GitHub repos that were either direct or indirect dependencies. I now have on my file system inside of my NewApp folder, all of the dependencies that are necessary for my application.

Additional Info

Register to get access to additional resources and info.