Swift Package Manager version Syntax

Kostiantyn Koval
Mar 23, 2016 · 1 min read

There is an amazing project called Swift Package Manager. I hope you know about it, if not take a second and have a look on it :)

Overview

Swift Package Manager (short name SwiftPM) is a dependency manger. You can make a Manifest file and declare your dependencies there.

import PackageDescription

let package = Package(
name: "Hello",
dependencies: [
.Package(url: "ssh://git@example.com/Greeter.git",
versions: Version(1,0,0)..<Version(2,0,0)),
]
)

In this example I simply say that my Package with name “Hello” depends on package with:

  • Url - ssh://git@example.com/Greeter.git
  • Version range - Version(1,0,0)..<Version(2,0,0)

That is the most popular notation to specify your dependency version. Maybe because it’s shown in the documentation.

But there are also many other formats to specify version dependency in the Manifest file.

Version formats

There are 5 formats to declare version specification for a Package dependency. Here are they:

  • Range - Version(0,1,0)..<Version(2,0,0)
  • MajorVersion - majorVersion: 0
  • majorVersion minor - majorVersion: 0, minor: 1
  • Version - Version(0, 1, 0)
  • Version String - “0.1.0”
let package = Package(
name: “App”,
dependencies: [
.Package(url: “../Foo”, versions:
Version(0,1,0)..<Version(2,0,0)),
.Package(url: “../Foo”, majorVersion: 0),
.Package(url: “../Foo”, majorVersion: 0, minor: 1),
.Package(url: “../Foo”, Version(0, 1, 0)),
.Package(url: “../Foo”, “0.1.0”),
]
)

That’s it :)

Now you know many ways to specify a version for a dependency Package, choose it wisely :)

Swift Programming

The Swift Programming Language

Kostiantyn Koval

Written by

iOS Dev. In love with iOS and Swift. “Swift High Performance” book author http://www.amazon.com/gp/product/B016BW45FQ

Swift Programming

The Swift Programming Language

More From Medium

More from Swift Programming

Related reads

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade