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
MAJOR
identifier of a version.Declaration
Swift
var major: UInt { get }
-
The
MINOR
identifier of a versionDeclaration
Swift
var minor: UInt? { get }
-
The
PATCH
identifer 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
SemVer
ranking 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) -> Bool
Return Value
true
if version objects are equal. -
===(_:
Extension method_: ) Strictly compares version objects for equality.
Declaration
Swift
static func === (lhs: Self, rhs: Self) -> Bool
Return Value
true
if version objects are strictly equal. -
hash(into:
Extension method) Conformance to
Hashable
protocol.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
SemVer
states two versions are compatible if they have the same major version.Declaration
Swift
func isCompatible(with version: Self) -> Bool
Parameters
version
A version object that conforms to the
SemanticVersionComparable
protocol.Return Value
true
if both versions have equal major versions. -
compare(with:
Extension method) Compare a object (lhs) conforming to
SemanticVersionComparable
with a greater version object (rhs). Lhs must be a lower version to return a valid result. Otherwise.noUpdate
will be returned regardless of the difference between the two version objects.Declaration
Swift
func compare(with version: Self) -> VersionCompareResult
Parameters
version
A version object that conforms to the
SemanticVersionComparable
protocol that will be compared.Return Value
A
VersionCompareResult
as 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.PATCH
part of a semantic version.Declaration
Swift
func hasEqualVersionCore(as version: Self) -> Bool
Parameters
version
A version object that conforms to the
SemanticVersionComparable
protocol.Return Value
true
if the respective version cores are equal.
-
absoluteString
Extension 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 }
-
coreString
Extension methodThe string of the version representing
MAJOR.MINOR.PATCH
only.Declaration
Swift
var coreString: String { get }
-
extensionString
Extension methodThe string of the version containing the pre-release identifier and build-meta-data only.
Declaration
Swift
var extensionString: String? { get }
-
prereleaseIdentifierString
Extension methodThe pre-release identifier as a string if available.
Declaration
Swift
var prereleaseIdentifierString: String? { get }
-
buildMetaDataString
Extension methodThe build-meta-data as a string if available.
Declaration
Swift
var buildMetaDataString: String? { get }