Subscribed unsubscribe Subscribe Subscribe

JPMartha's Pancake

This blog is the way to brush up my poor English.

How to Depend on a Pre-release Versions of Package with the Swift Package Manager 🆙

Swift Package Manager Swift English

After I had posted the previous entry , @norio_nomura taught me the following:

So, I organized that. Thanks @norio_nomura ! 🙏

Overview

  • 2.0.0-beta.1 has a lower precedence than 2.0.0.
  • Set majorVersion: 2, then 2.0.0-beta.1 is not included.
  • Set majorVersion: 1, then 2.0.0-beta.1 is not included.
  • Set versions: Version(1,0,0)..<Version(2,0,0), then 2.0.0-beta.1 is included.
  • To specify 2.0.0-beta.1, set the following: 🆕
Version(2, 0, 0, prereleaseIdentifiers: ["beta", "1"])

Note

Semantic Versioning

Swift packages are expected to follow Semantic Versioning.

Swift packages are expected to follow Semantic Versioning (SemVer), a standard for assigning version numbers to software releases.


swift-package-manager/PackageManagerCommunityProposal.md at master · apple/swift-package-manager · GitHub

Pre-release versions have a lower precedence than the associated normal version.

Pre-release versions have a lower precedence than the associated normal version. A pre-release version indicates that the version is unstable and might not satisfy the intended compatibility requirements as denoted by its associated normal version. Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7, 1.0.0-x.7.z.92.


Semantic Versioning 2.0.0

For example, 2.0.0-beta.1 has a lower precedence than 2.0.0.

Implementation

swift-package-manager/Package.swift at swift-DEVELOPMENT-SNAPSHOT-2016-03-01-a · apple/swift-package-manager · GitHub

public class func Package(url url: String, versions: Range<Version>) -> Dependency {
    return Dependency(url, versions)
}

public class func Package(url url: String, majorVersion: Int) -> Dependency {
    return Dependency(url, Version(majorVersion, 0, 0)..<Version(majorVersion, .max, .max))
}

Set majorVersion: 2

2.0.0-beta.1 is not included.

Version(2, 0, 0)..<Version(2, .max, .max)

Set majorVersion: 1

2.0.0-beta.1 is not included.

Version(1, 0, 0)..<Version(1, .max, .max)

Set versions: Version(1,0,0)..<Version(2,0,0)

2.0.0-beta.1 is included.

Package.swift — The Manifest File

Here's an example of a Package.swift file to specify 2.0.0-beta.1: 🆕

import PackageDescription

let package = Package(
    name: "TryKit",
    dependencies: [
        .Package(url: "https://github.com/ikesyo/Himotoki.git",
            Version(2, 0, 0, prereleaseIdentifiers: ["beta", "1"]))
    ]
)
$ swift build

👇

Himotoki-2.0.0-beta.1 is downloaded. 🤔

Cloning https://github.com/ikesyo/Himotoki.git

Resolved version: 2.0.0-beta.1

...