Swiftpack.co - Package - mflknr/SwiftVersionCompare

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.

mflknr/SwiftVersionCompare

Compare semantic versions in swift.

SwiftVersionCompare

platforms languages build doccov codecov

A small package for comparing and utilizing versions conforming to SemVer.

Following features are and will be implemented:

  • ☑ Create SemanticVersionComparable protocol to handle comparison methods
  • ☑ Compare versions using Equatable and Comparable with the known operators ==, ===, <, <=, > and >=.
  • ☑ Compare versions and get the severity of the update (e. g. major-update).
  • ☐ Compare equal versions with different pre-release and build metadata.
  • ☐ Utilize ranges for a greater variaty of comparisons.
  • ☑ Create a version from major, minor, patch and extension information.
  • ☑ Create a version from string using LosslessStringConvertible or ExpressibleByStringLiteral .
  • ☑ Extend Bundle and ProcessInfo for easy usage.
  • ☑ Open documentation.

Installation

Swift Package Manager:

package(url: https://github.com/mflknr/SwiftVersionCompare.git", from: "0.6.0"))

Usage

For implenentation details see the documentation.

// use the version identifier for initialization
let versionOne = Version(1, 0, 0)
let versionTwo = Version(
    major: 1,
    minor: 0,
    patch: 0
)

// use strings
// use `ExpressibleByStringLiteral` with caution. it's fatal if the string is not a `SemVer` version
let versionThreeA: Version = "1.0.0" 
let versionThreeB: Version = Version("1.0.0")

// using the optional type is safe
let versionFourA: Version? = "1.0.0"
let versionFourB: Version? = Version("1.0.0")

// easy initial `0.0.0` version
let initialVersion: Version = .initial

// from bundle and processInfo
let bundleVersion = Bundle.main.shortVersion
let osVersion = ProcessInfo.processInfo.comparableOperatingSystemVersion

// compare versions with usally known operators (==, ===, <, <=, >=, >)
if Version("1.0.0") > Version("0.4.0") {
    // ...
}

// compare versions and get update severity
let currentVersion = Version("0.6.0")
let newVersion = Version("1.0.0")

if currentVersion.severity(to: newVersion) == .major {
    // ...
}

If you want to implement yourself a custom version object, feel free to let it conform to the SemanticVersionComparable protocol enabling it with all the comparable and equatable operators.

Github

link
Stars: 1
Last commit: 5 days ago

Releases

0.6.0 - 2021-01-06T23:44:58

Initial published setup of this package. Create a version from string, using major, minor, patch and extensions, from Bundle or from ProcessInfo. Compare two versions with common operators (==, ===, <, <=, >, >=) or get the severity of an update.