The string initializer Semver.init?(_:) always produce valid version (or nil). The literal initializer Semver.init(stringLiteral:) only accept StaticString and crash when failed.
However, the member wise initializer Semver.init(major:minor:patch:prerelease:buildMetadata:) doesn’t perform validity checks on its fields. It’s possible to form an invalid version. You can manually validate a version using Semver.isValid.
let version = Semver(major: 0, minor: 0, patch: -1) // invalid version 0.0.-1
version.isValid // false
Semver
Semver is a Swift implementation of the Semantic Versioning.
Requirements
Usage
Quick Start
Equality
The
Equatable
conformance respect Semver semantic equality and ignore build metadata. This also affectComparable
andHashable
.You can use
===
and!==
to take build metadata into account.Validity Check
The string initializer
Semver.init?(_:)
always produce valid version (or nil). The literal initializerSemver.init(stringLiteral:)
only acceptStaticString
and crash when failed.However, the member wise initializer
Semver.init(major:minor:patch:prerelease:buildMetadata:)
doesn’t perform validity checks on its fields. It’s possible to form an invalid version. You can manually validate a version usingSemver.isValid
.Installation
Swift Package Manager
Add the project to your
Package.swift
file:Carthage
Add the project to your
Cartfile
:Copy File
This is a lightweight library contains only one file. You can simply copy/paste the Semver file into your project.
License
Semver is available under the MIT license. See the LICENSE file.