语义化版本 (SemanticVersion)

SemanticVersion 是一个稍稍偏离规范(但更好!)的 Semantic Version 2.0.0 在 Swift 中的实现。它支持 Codable、Comparable、Equatable 和 Hashable 协议。主要特性:

import SemanticVersion

let v1 = SemanticVersion(1)
let v12 = SemanticVersion(1, 2)
let v123 = SemanticVersion(1, 2, 3)
let v123β = SemanticVersion(1, 2, 3, "beta")
let v123β_localBuild = SemanticVersion(1, 2, 3, "beta", "local-202307081341")

let v2 = SemanticVersion("2")!
let v20 = SemanticVersion("2.0")!
let v201 = SemanticVersion("2.0.1")!

if v2 == v20 {
    print("They ARE equal")
}

print("Is v2.0.1 newer than v2.0? " + v201 > v20 ? "Yes!" : "No!")

let v3_local = SemanticVersion("3-beta+local")
let v3_test = SemanticVersion("3-beta+test")

if v3_local == v3_test {
    print("Local version 3.0.0-beta is indeed the same as test version 3.0.0-beta (according to spec)")
}