Structures
The following structures are available globally.
-
A version type conforming to
SemanticVersionComparable
and thereforSemVer
.You can create a new version using strings, string literals and string interpolations, formatted like
MAJOR.MINOR.PATCH-PRERELEASE+BUILD
, or memberwise initialization.// from string let version: Version? = "1.0.0" let version: Version? = Version("1.0.0-alpha.1+23") let version: Version? = Version("1.0.0.1.2") // <- will be `nil` since it's not `SemVer` let version: Version = "1.0.0" // <- will crash if string does not conform to `SemVer` // from memberwise properties let version: Version = Version(1, 0, 0) let version: Version = Version(major: 1, minor: 0, patch: 0, prerelease: ["alpha, "1"], build: ["exp"])
Pre-release identifiers or build-meta-data can be handled as strings or as enum cases with it associated raw values (see
PrereleaseIdentifier
andBuildMetaData
for more).let version: Version = Version(major: 1, minor: 0, patch: 0, prerelease: ["alpha"], build: ["500"]) version.absoluteString // -> "1.0.0-alpha+500" let version: Version = Version(2, 32, 16, ["family", .alpha], ["1"]) version.absoluteString // -> "2.32.16-family.alpha+1" version.coreString // -> "2.32.16" version.extensionString // -> "family.alpha+1" version.prereleaseIdentifer // -> "family.alpha" version.buildMetaDataString // -> "1"
Remark
See semver.org for detailed information.Declaration
Swift
public struct Version : Sendable, SemanticVersionComparable
extension Version: LosslessStringConvertible
extension Version: ExpressibleByStringLiteral
extension Version: ExpressibleByStringInterpolation
extension Version: CustomDebugStringConvertible