Cartfile: Creating your first Carthage Cartfile

In this lesson

In this lesson, I’ll show you how to create your first Cartfile, how to add application dependencies to it and specify the versions of those dependencies.


Tap on time to skip ahead


Ok, are you ready? We’re going to create our first Cartfile. I’ve determined that I’m going to create an application and I want to use the following frameworks. I want to use RxSwift- all of these are GitHub repos, open source- I want to use AlamofireImage, I want to use SwiftyBeaver for logging, Swinject, which is a dependency injection framework for Swift. And I’ve got a couple of my own, LoL Data Dragon Content Provider and a Swift Adapters fmdb. For the point of this video lesson, it’s not important what my two libraries do.


Let’s create our first Cartfile so that we can get our dependencies to build our application. In order to do so, I’ve opened up the terminal and I’m in the iOS folder here. I’m going to make a new directory that’s going to contain a MyNewApp folder. This is where I’m going to place my new application. You’ll see there’s nothing in there at this point. I’m starting from the very beginning.


I’ve opened my text editor here on my left. I’m using Atom. You can use whatever you want. You can use TextEdit or BBEdit or whatever text editor you prefer. The first thing I’m going to do is start declaring my dependencies. We start off with what’s called the origin. The origin currently can only be a GitHub or a GitHub Enterprise repository. We’re going to specify the repo name, which, if you look for the repo, it’s right here. It’s ReactiveX/RxSwift. I’m going to repeat that for every dependency of my application. If you’ll bear with me here, there’s a little bit of typing. This one is Alamofire, AlamofireImage. The next one is SwiftyBeaver, and I know what that one is so I don’t need to look. The next one is Swinject, and I also know what that one is. Then, I have my own two frameworks, which are JeffBNimble/lol-datadragon-content-provider, and the last one is JeffBNimble/swift-adapters-fmdb.


I’ve specified all my dependencies. This is, as I said, this is called the origin. This identifies every repo that is a dependency for the application that I’m going to build.


While this cartfile is perfectly valid in it’s current form, I want to specify version requirements for each of my dependencies. Let’s start with RxSwift. What I’m going to do is navigate to the releases tab and find the latest version. In this case it is 2.4.0. I’m going to use the double = which means “resolve to that exact version.” There are other ways, other identifiers that you can use, I’ll go over those in just a second.


The next library, of course, is Alamofire, I’ve written all these down already so that one happens to be 2.4.0 as well. SwiftyBeaver is 0.5.2. Swinject is 1.1.1. My own dataDragon is 0.0.18 and my fmdb adapters library is 0.0.14. That’s the typical way to create a Cartfile and we’re ready to resolve our dependencies.


What I’m going to do now is save this file as a Cartfile with the name Cartfile. Let me pick the folder where I want to put that. We want to put that here, /Development/iOS/MyNewApp and we’re going to call it Cartfile. Let’s save that. Then if I head over to the terminal you can see that I now have a Cartfile in /MyNewApp folder. If we have a look at it, it is, of course, what we typed and specified for our dependencies.