Structure
Version
public struct Version: Codable, Comparable, LosslessStringConvertible
A struct representing a "semantic versioning" version number.
While this struct tries to follow the SemVer 2.0.0 as close as possible, it takes some liberties for simplicity and convenience sake:
-
String version numbers omitting a "patch" component are accepted, and their
patch
component defaults to0
. -
"Pre-release" version numbers (with an hyphen after the patch component) are currently not supported.
Relationships
Conforms To
Codable
Comparable
LosslessStringConvertible
Initializers
init?(_:)
public init?(_ description: String)
Instantiates a version number from a string representation.
The string will be parsed and the expected formats are either:
-
"MAJOR.MINOR", or
-
"MAJOR.MINOR.PATCH"
In the first case, the patch component of the version will default to 0
.
If the parsed string is not in a valid format, the initializer will fail and return nil
.
Parameters
Name | Type | Description |
---|---|---|
value | The formatted version number. |
init(from:)
public init(from decoder: Decoder) throws
Creates a new instance by decoding from the given decoder.
This initializer throws an error if reading from the decoder fails, or if the data if not in the expected version number format.
Parameters
Name | Type | Description |
---|---|---|
decoder | Decoder |
The decoder to read data from. |
Properties
Methods
encode(to:)
public func encode(to encoder: Encoder) throws
Encodes this value into the given encoder.
If the value fails to encode anything, encoder
will encode an empty keyed container in its place.
This function throws an error if any values are invalid for the given encoder's format.
Parameters
Name | Type | Description |
---|---|---|
encoder | Encoder |
The encoder to write data to. |
Operators
<
Returns a Boolean value indicating whether the value of the first argument is less than that of the second argument.
A version number is considered less than another version number if any of its components, starting from major
and ending with patch
, is less than same component of the other version number.
Parameters
Name | Type | Description |
---|---|---|
lhs | Version |
A value to compare. |
rhs | Version |
Another value to compare. |
==
Returns a Boolean value indicating whether two version numbers are equal.
Two version numbers are equal if all their components are equal.
Parameters
Name | Type | Description |
---|---|---|
lhs | Version |
A value to compare. |
rhs | Version |
Another value to compare. |