Carthage dependency versions: Flexibly specify dependency versions

In this lesson

This lesson will show you all of the various ways that you can specify dependency versions. 

Transcript

Tap on time to skip ahead

00:10

Like most other package managers, Carthage provides a very flexible mechanism to specify dependency versions. I, as you can see here, have specified all of my dependencies and I’m tying them to a specific version using the == sign. That means that this dependency will always resolve to this version no matter if the RxSwift committers release a new version, I will always pull this version. If I want a different version, I have to update my Cartfile. This is the way I choose to express my dependencies, but there are many other ways.

00:55

Let’s say, for example, that I wanted to specify a version requirement that says, “give me anything greater than 2.4.0.” Today, if I look at my releases, 2.4.0 is the latest release, but if RxSwift had a version release tomorrow that was 2.5.0, if I ran Carthage again to resolve all my dependencies, this version requirement of greater than or equal to 2.4.0, would automatically pull the latest version available at the time I run Carthage.

01;35

The next way I can specify dependencies is to use a compatibility specifier. That means, anything that is compatible with 2.4.0. If we look here, actually, let me change this to 2.3.0. If we look here over at the releases and scroll backwards, we can see that there was a 2.3.1 release and a 2.3.0 release. If I resolved my dependencies way back here on March 18 when 2.3.0 was released, I would have pulled 2.3.0. A couple of days later, six days later, or four days later I should say, a new version came out 2.3.1. According to semantic versioning, this is a compatible version with 2.3.0. If I were to run Carthage again with this same version specifier, it would have pulled 2.3.1. Then we can see here, later, that 2.4.0 was released. According to semantic versioning, that version, 2.4.0, is not compatible with 2.3.0 version identifier. Even though a new release came out, this version specifier would not pull the 2.4 version or the latest version available.

03:11

Aside from version numbers, we can use other things. The first thing that I’m going to show you is that we can resolve our dependencies using specific branches. Let’s take a look at the branches here of RxSwift. You’ll see that there are quite a few different branches. At this point there are 17. Let’s say I was interested in this swift-3.0 branch. All I would have to do is specify swift-3.0 and when I run Carthage it will pull the latest commits to this branch. The thing to be aware of when you do something like this is that every day you can expect that the committers are committing code to this branch. This kind of version specifier will pull the latest code that has been committed to this branch and that possibly could break your application if the committers introduce a bug or something that hasn’t been fully tested. Use these sorts of version specifiers at your own risk.

04:20

The final way you can specify a version is that you can actually tie a version of one of your dependencies to a specific commit to the repository. Let’s go take a look at all the commits and you can see here that there are commits almost daily to this repository. Let’s say that I want to tie this version to a specific commit. Let’s say this one right here, Grammar fix in intro playground. If I scroll over here, you’ll notice that there is an identifier for that specific commit and I can copy that sha or that identifier to the clipboard and paste it as my version requirement for this dependenciy. Therefore, RxSwift is now tied to that specific commit. Every time I run Carthage, it will always resolve to this specific commit in the repository.

05:16

Let’s summarize. Here I have the same dependency specified all the different ways that we can resolve the dependency to a specific version using different types of version identifiers. Here is the ==, this ties to a specific version. This is the greater than or equal to. This is the compatible version identifier. This is tied to a specific branch, tied to a specific tag, and tied to a specific commit. As you can see, Carthage very flexibly allows you to specify your version requirements for all of your dependencies.

Additional Info

Register to get access to additional resources and info.