Swift.iOS: CocoaPods – Pod Versions

In this lesson

There are a few different operators to calculate the desired version numbers of a CocoaPod before you even install it. Let’s go through each way you can filter and determine the optimal version of a pod for your project to keep your code up to date but to also keep from breaking any of your hard work.

Kyle Roberts
Swift Guru at Large

Kyle's Series

Transcript

Tap on time to skip ahead

00:11

Hello world. Kyle here with Brax.tv. Let’s talk about how to work with version numbers in your Podfile when using CocoaPods. What I’ve done for each of these pod lines is I’ve gone to CocoaPods.org and I have searched for the CocoaPod that I want. I’m searching for Alamofire, for example, because it is the most popular Swift library on GitHub, at least the most starred. We can see that it’s the first entry here, Alamofire with a version number of 3.4. There’s a little clipboard button next to it that we can click to copy that entry and copy that in here.

00:58

There has been a version update since I did this, because I was on 3.3, but what is this tilde and caret? What is it? What does it mean? It’s called the optimistic version operator. What that means is that the version that is specified next to it, 3.4, is going to be the minimum version that CocoaPods attempts to install. Not only that, if there were to be a 3.4.1 release, then CocoaPods would also be able to install that.

01:37

Even though the current version number is 3.4.0, the value we copied was only 3.4. That means that this optimistic operator is going to attempt to install the most recent version number of Alamofire up to but not including 3.5. Since we’re specified 3.4, we could be installing Alamofire versions all the way up to 3.4.9 repeating. Since we are not specifying 3.5, we are not going to install anything 3.5.

02:19

If we would bring that back to just 3, that means we could install anything up to 3.9.9.9.9, all of that. But, if they came out with Alamofire version 4.0.0 and we still had a 3 here, we would not install that. The purpose of this is that if you specify an X.X version number, then they are assuming that any minor updates to that, a third .X in the version number, would not be anything that would break your app or force you to make a bunch of code changes. They might just include bug fixes or little tweaks. That sort of stuff. So this is great to use.

03:04

There are a couple other operators that you could use when working with versions in CocoaPods. I guess one option that we could have covered first is no operator at all. In this situation, CocoaPods is only going to install a version 3.4. We may even want to get more specific and say, only install version 3.4.1. That’s no operator.

03:27

There’s also a few simpler logic operators. You could use greater than, I guess that was less than, greater than, both of those. Greater than or equal to. Or less than or equal to. What if version 3.4 of Alamofire only supported iOS 9? I’m just making this up, this isn’t true. I’m sure it supports versions before that. We want a version less than 3.4 so we can just use the less than operator. CocoaPods then will install the most recent version of Alamofire that is less than 3.4. If we said, less than or equal to, than as long as there’s a version 3.4, we’ll download that. If not, we’ll download the most recent version underneath. Same thing with greater than. Which is great.

04:30

In most cases, I have really only used the optimistic operator or just no operator. But I’m sure these other logic ones will come in plenty of handy for some people.

Additional Info

Register to get access to additional resources and info.