22

GitHub - mxcl/Version: semver (Semantic Version) Swift µFramework.

 5 years ago
source link: https://github.com/mxcl/Version
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

Version badge-platforms badge-languages badge-ci badge-jazzy badge-codecov

A µ-framework for representing, comparing, encoding and utilizing semantic versions, eg. 1.2.3 or 2.0.0-beta.

This is Version.swift from the Swift Package Manager, with some minor adjustments:

  1. More compact Codable implementation †
  2. Implements LosslessStringConvertible
  3. Not a massive-single-source-file (MSSF)
  4. Online documentation
  5. Extensions for Bundle and ProcessInfo
  6. Removal of the potentially fatal ExpressibleByStringLiteral conformance
  7. A “tolerant” initializer for user input like 10.0 or 3
  8. Idiomatic implementations for Range<Version>

We have automatic monitoring for changes at Apple’s repo to alert us if we should need merge any fixes.

Semantic versions can be losslessly expressed as strings; thus we do so.

‡ Like Int we can losslessly store a semantic version from a valid string, so we conform to the same protocol.

Support mxcl

Hey there, I’m Max Howell. I’m a prolific producer of open source software and probably you already use some of it (for example, I created brew). I work full-time on open source and it’s hard; currently I earn less than minimum wage. Please help me continue my work, I appreciate it ??

68747470733a2f2f63352e70617472656f6e2e636f6d2f65787465726e616c2f6c6f676f2f6265636f6d655f615f706174726f6e5f627574746f6e4032782e706e67

Other ways to say thanks.

Usage

import Version

// these two initializers are the same, use whichever suits the code context
let v1 = Version(1,0,0)
let v2 = Version(major: 1, minor: 0, patch: 0)

let v3 = Version("1.2.3")           // =>  1.2.3: Version?
let v4 = Version(tolerant: "10.1")  // => 10.1.0: Version?
let v5 = Version(tolerant: "10")    // => 10.0.0: Version?

// a real Version object from your app’s Info.plist
let v6 = Bundle.main.version

let range = Version(1,2,3)..<Version(2,0,0)

let null: Version = .null  // => Version(0,0,0)

let foo = Version(1,2,3) < Version(2,0,0)  // => true

Installation

SwiftPM:

package.append(.package(url: "https://github.com/mxcl/Version.git", from: "1.0.0"))

Carthage:

Waiting on: @Carthage#1945.

Ranges

Ranges work as you expect, but there are caveats for prerelease identifiers, here are the rules:

1.0.0..<2.0.0 does not include eg. 2.0.0-alpha

This is probably what you expected. However:

1.0.0..<2.0.0 also does not include eg. 1.5.0-alpha

However:

1.0.0..<2.0.0-beta does include eg. 2.0.0-alpha

This is how the majority of Semantic Version libraries work.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK