SemanticVersioningKit 是一个小型库,用于创建和解析符合 语义化版本 规范的版本表示。
要使用 Apple 的 Swift 包管理器进行集成,请将以下内容作为依赖项添加到您的 Package.swift
文件中
dependencies: [
.package(url: "https://github.com/alexanderwe/SemanticVersioningKit.git", from: "2.1.2")
]
或者,导航到您的 Xcode 项目,选择 Swift Packages
,然后单击 +
图标以搜索 SemanticVersioningKit
。
如果您不喜欢使用上述任何依赖项管理器,您可以手动将 SemanticVersioningKit
集成到您的项目中。只需将 Sources
文件夹拖到您的 Xcode 项目中即可。
首先导入 SemanticVersioningKit
import SemanticVersioningKit
定义一个 SemanticVersion
实例
let version = SemanticVersion(major: 1, minor: 0, patch: 0) // "1.0.0"
let versionWithAdditions = SemanticVersion(major: 1, minor: 0, patch: 0, preReleaseIdentifiers: ["alpha", "1"], buildIdentifiers: ["exp","sha","5114f85"]) // "1.0.0-alpha.1+exp.sha.5114f85"
也可以从 String
表示创建 SemanticVersion
。请注意,由于使用的 String
不符合语义化版本格式,因此初始化可能会失败。
let version = try SemanticVersion(input: "1.0.0")
let failed = try SemanticVersion(input: ".0.0")
非常欢迎贡献 🙌