Semver is a Swift implementation of the Semantic Versioning.
- Swift 5.0+
import Semver
// A leading "v" character is ignored.
let version = Semver("v1.3.8-rc.1+build.3")!
version > Semver("1.0.2+39f1d74")! // true
The Equatable
conformance respect Semver semantic equality and ignore build metadata. This also affect Comparable
and Hashable
.
You can use ===
and !==
to take build metadata into account.
let v1 = Version("1.0.0+100")!
let v2 = Version("1.0.0+200")!
v1 == v2 // true
v1 <= v2 // true
v1.hashValue == v2.hashValue // true
Set([v1, v2]).count == 1 // ❗️true
v1 === v2 // false
v1 !== v2 // true
The string initializer Semver.init?(_:)
always produce valid version (or nil). The literal initializer Semver.init(stringLiteral:)
only accept StaticString
and crash when failed.
However, the member wise initializer Semver.init(major:minor:patch:prerelease:buildMetadata:)
doesn't perform validity checks on its fields. It's possible to form an invalid version. You can manually validate a version using Semver.isValid
.
let version = Semver(major: 0, minor: 0, patch: -1) // invalid version 0.0.-1
version.isValid // false
Add the project to your Package.swift
file:
package.dependencies += [
.package(url: "https://github.com/ddddxxx/Semver", .upToNextMinor("0.2.0"))
]
Add the project to your Cartfile
:
github "ddddxxx/Semver"
This is a lightweight library contains only one file. You can simply copy/paste the Semver file into your project.
Semver is available under the MIT license. See the LICENSE file.