Structure

Version

A version according to the semantic versioning specification.

Declaration

struct Version

Overview

A package version is a three period-separated integer, for example 1.0.0. It must conform to the semantic versioning standard in order to ensure that your package behaves in a predictable manner once developers update their package dependency to a newer version. To achieve predictability, the semantic versioning specification proposes a set of rules and requirements that dictate how version numbers are assigned and incremented. To learn more about the semantic versioning specification, visit semver.org.

The major version

The first digit of a version, or major version, signifies breaking changes to the API that require updates to existing clients. For example, the semantic versioning specification considers renaming an existing type, removing a method, or changing a method’s signature breaking changes. This also includes any backward-incompatible bug fixes or behavioral changes of the existing API.

The minor version

Update the second digit of a version, or minor version, if you add functionality in a backward-compatible manner. For example, the semantic versioning specification considers adding a new method or type without changing any other API to be backward-compatible.

The patch version

Increase the third digit of a version, or patch version, if you’re making a backward-compatible bug fix. This allows clients to benefit from bugfixes to your package without incurring any maintenance burden.

Topics

Creating a Version

init(Version)

Initializes and returns a newly allocated version struct for the provided version.

init?(String)

Initializes and returns a newly allocated version struct for the provided version string.

init(Int, Int, Int, prereleaseIdentifiers: [String], buildMetadataIdentifiers: [String])

Initializes and returns a newly allocated version struct for the provided components of a semantic version.

init(extendedGraphemeClusterLiteral: String)

Initializes and returns a newly allocated version struct for the provided extended grapheme cluster.

init(stringLiteral: String)

Initializes and returns a newly allocated version struct for the provided string literal.

init(unicodeScalarLiteral: String)

Initializes and returns a newly allocated version struct for the provided Unicode string.

Describing a Semantic Version

let major: Int

The major version according to the semantic versioning standard.

let minor: Int

The minor version according to the semantic versioning standard.

let patch: Int

The patch version according to the semantic versioning standard.

let prereleaseIdentifiers: [String]

The pre-release identifier according to the semantic versioning standard, such as -beta.1.

let buildMetadataIdentifiers: [String]

The build metadata of this version according to the semantic versioning standard, such as a commit hash.

var description: String

A textual description of the version object.

Operator Functions

static func != (Version, Version) -> Bool

Returns a Boolean value indicating whether two values are not equal.

static func ... (Version) -> PartialRangeFrom<Version>

Returns a partial range extending upward from a lower bound.

static func ... (Version) -> PartialRangeThrough<Version>

Returns a partial range up to, and including, its upper bound.

static func ... (Version, Version) -> ClosedRange<Version>

Returns a closed range that contains both of its bounds.

static func ..< (Version) -> PartialRangeUpTo<Version>

Returns a partial range up to, but not including, its upper bound.

static func ..< (Version, Version) -> Range<Version>

Returns a half-open range that contains its lower bound but not its upper bound.

static func < (Version, Version) -> Bool

Returns a Boolean value indicating whether the value of the first argument is less than that of the second argument.

static func > (Version, Version) -> Bool

Returns a Boolean value indicating whether the value of the first argument is greater than that of the second argument.

static func <= (Version, Version) -> Bool

Returns a Boolean value indicating whether the value of the first argument is less than or equal to that of the second argument.

static func >= (Version, Version) -> Bool

Returns a Boolean value indicating whether the value of the first argument is greater than or equal to that of the second argument.

Encoding and Decoding

func encode(to: Encoder)

Encodes this value into the given encoder.

See Also

Describing a Package Dependency

let url: String

The Git url of the package dependency.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software