Updated to Swift 5 (#4) Adds Argument Label(string, number), Updated to Swift5
Updated to Swift 5 (#4)
Semantic Versioning implementation in Swift. Semver represent a semantic version according to the Semantic Versioning Specification.
Semver
Semver doesn’t contain any external dependencies. These are currently support options:
# Podfile user_framework! target 'YOUR_TARGET_NAME' do pod 'Semver.swift' end
Replace YOUR_TARGET_NAME and then, in the Podfile directory, type:
YOUR_TARGET_NAME
Podfile
$ pod install
Create a Package.swift file.
Package.swift
// swift-tools-version:5.1 import PackageDescription let package = Package( name: "NAME", dependencies: [ .package(url: "https://github.com/glwithu06/Semver.swift.git", from: "SEMVER_TAG") ], targets: [ .target(name: "NAME", dependencies: ["Semver"]) ] )
Replace SEMVER_TAG and then type:
SEMVER_TAG
$ swift build
Semver can be instantiated directly:
let version = Semver(major: 1, minor: 23, patch: 45, prereleaseIdentifiers: ["rc", "1"], buildMetadataIdentifiers: ["B001"])
minor, patch are optional parameters default to “0”.
minor
patch
prereleaseIdentifiers, buildMetadataIdentifiers are optional parameters default to [].
prereleaseIdentifiers
buildMetadataIdentifiers
[]
You can create Semver from String.
let version = try Semver(string: "1.23.45-rc.1+B001")
or from Numeric.
let version = try Semver(number: 1.23)
let version = try Semver(number: 10)
If the version is invalid, it throws a ParsingError.
ParsingError
Semver conforms to ExpressibleByStringLiteral, ExpressibleByIntegerLiteral, ExpressibleByFloatLiteral.
ExpressibleByStringLiteral
ExpressibleByIntegerLiteral
ExpressibleByFloatLiteral
It can convert a String to Semver.
String
let version: Semver = "1.23.45-rc.1+B001"
or Numeric to Semver.
Numeric
let version: Semver = 1
let version: Semver = 1.23
⚠️ If the version is invalid, Semver represents “0.0.0”. It doesn’t throw any errors.
The default operators for comparsion are implemented(< , <= , > ,>= ,== , !=).
<
<=
>
>=
==
!=
This will comapre major, minor, patch and the prerelease identifiers according to the Semantic Versioning Specification.
Any pull requests and bug reports are welcome!
Feel free to make a pull request.
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
Semantic Versioning
Semantic Versioning implementation in Swift.
Semver
represent a semantic version according to the Semantic Versioning Specification.Requirements
Installation
Semver
doesn’t contain any external dependencies. These are currently support options:Cocoapods
Replace
YOUR_TARGET_NAME
and then, in thePodfile
directory, type:Swift Package Manager
Create a
Package.swift
file.Replace
SEMVER_TAG
and then type:Usage
Create
Semver
can be instantiated directly:minor
,patch
are optional parameters default to “0”.prereleaseIdentifiers
,buildMetadataIdentifiers
are optional parameters default to[]
.Parse
You can create
Semver
from String.or from Numeric.
If the version is invalid, it throws a
ParsingError
.Extensions
Semver
conforms toExpressibleByStringLiteral
,ExpressibleByIntegerLiteral
,ExpressibleByFloatLiteral
.It can convert a
String
toSemver
.or
Numeric
toSemver
.⚠️ If the version is invalid,
Semver
represents “0.0.0”. It doesn’t throw any errors.Compare
The default operators for comparsion are implemented(
<
,<=
,>
,>=
,==
,!=
).This will comapre major, minor, patch and the prerelease identifiers according to the Semantic Versioning Specification.
Contribution
Any pull requests and bug reports are welcome!
Feel free to make a pull request.