SemanticVersionComparable
public protocol SemanticVersionComparable : Comparable, Hashable
A type that can be expressed and utilized as a semantic version conforming to SemVer.
Additionally to the ranking and comparison rules if their version core identifiers are nil they
will be treated as 0.
let versionOne = Version(1, 0, 0)
let versionTwo = Version(1)
versionOne == versionTwo // <- this statement is `true`
You can choose between a loosly or strictly comparison considering if you want to include the build-meta-data of versions when comparing:
let versionOne = Version(1, 0, 0, [.alpha])
let versionTwo = Version(1, 0, 0, [.alpha], ["exp"])
versionOne == versionTwo // `true`
versionOne === versionTwo // `false`
Remark
See semver.org for detailed information.-
The
MAJORidentifier of a version.Declaration
Swift
var major: UInt { get } -
The
MINORidentifier of a versionDeclaration
Swift
var minor: UInt? { get } -
The
PATCHidentifer of a verion.Declaration
Swift
var patch: UInt? { get } -
Pre-release identifier of a version.
Declaration
Swift
var prerelease: [PrereleaseIdentifier]? { get } -
Build-meta-data of a version.
Declaration
Swift
var build: [BuildMetaData]? { get } -
<(_:Extension method_: ) Compare versions using the
SemVerranking system.Note
Build-meta-data have no influence on a version’s rank.Declaration
Swift
static func < (lhs: Self, rhs: Self) -> Bool -
==(_:Extension method_: ) Compares version objects for equality.
Declaration
Swift
static func == (lhs: Self, rhs: Self) -> BoolReturn Value
trueif version objects are equal. -
===(_:Extension method_: ) Strictly compares version objects for equality.
Declaration
Swift
static func === (lhs: Self, rhs: Self) -> BoolReturn Value
trueif version objects are strictly equal. -
hash(into:Extension method) Conformance to
Hashableprotocol.Note
Since build-meta-data are not considered in ranking semantic version, it won’t be considered here either.Declaration
Swift
func hash(into hasher: inout Hasher) -
isCompatible(with:Extension method) A boolean value indicating the compatibility of two versions. As
SemVerstates two versions are compatible if they have the same major version.Declaration
Swift
func isCompatible(with version: Self) -> BoolParameters
versionA version object that conforms to the
SemanticVersionComparableprotocol.Return Value
trueif both versions have equal major versions. -
compare(with:Extension method) Compare a object (lhs) conforming to
SemanticVersionComparablewith a greater version object (rhs). Lhs must be a lower version to return a valid result. Otherwise.noUpdatewill be returned regardless of the difference between the two version objects.Declaration
Swift
func compare(with version: Self) -> VersionCompareResultParameters
versionA version object that conforms to the
SemanticVersionComparableprotocol that will be compared.Return Value
A
VersionCompareResultas the severity of the update. -
hasEqualVersionCore(as:Extension method) Check if a version has an equal version core as another version.
Note
A version core is defined as the
MAJOR.MINOR.PATCHpart of a semantic version.Declaration
Swift
func hasEqualVersionCore(as version: Self) -> BoolParameters
versionA version object that conforms to the
SemanticVersionComparableprotocol.Return Value
trueif the respective version cores are equal.
-
absoluteStringExtension methodThe absolute string of the version containing the core version, pre-release identifier and build-meta-data formatted as
MAJOR.MINOR.PATCH-PRERELEASE+BUILD.Declaration
Swift
var absoluteString: String { get } -
coreStringExtension methodThe string of the version representing
MAJOR.MINOR.PATCHonly.Declaration
Swift
var coreString: String { get } -
extensionStringExtension methodThe string of the version containing the pre-release identifier and build-meta-data only.
Declaration
Swift
var extensionString: String? { get } -
prereleaseIdentifierStringExtension methodThe pre-release identifier as a string if available.
Declaration
Swift
var prereleaseIdentifierString: String? { get } -
buildMetaDataStringExtension methodThe build-meta-data as a string if available.
Declaration
Swift
var buildMetaDataString: String? { get }