Skip to content

AlexanderNey/SemanticVersioning

Repository files navigation

Semantic Versioning

Twitter: @ajax64 Platform Platform License Build and Test Swift Version

Semantic Versioning implementation in Swift! Use the struct Version to represent a version according to the Semantic Versioning Specification 2.0.0.

✅ Fully Unit tested

✅ 100% Swift

Getting Started

Requirements

  • iOS 11.0+ / Mac OS X 10.13+
  • Xcode 11+
  • Swift 5.0

Installation

The easiest way to use SemanticVersion in your project is using the CocaPods package manager.

Swift PM

See Adding Package Dependencies to Your App on how to use this library with Swift PM.

CocoaPods

See installation instructions for CocoaPods if not already installed

To integrate the library into your Xcode project specify the pod dependency to your Podfile:

platform :ios, '11.0'
use_frameworks!

pod 'SemanticVersioning'

run pod install

pod install

Usage

Create version 2.0.0

let version = Version(major: 2)

Create version 1.2.3

let version = Version(major: 1, minor: 2, patch: 3)

Create version 1.0.0-alpha.2

let version = Version(major: 1, preReleaseIdentifier: ["alpha", "2"])

Create version from a String

let version: Version = "1.3.10-rc"

Create a list of versions from a Array of Strings

let versions: [Version] = ["1.0.0-alpha", "1.0.0-alpha.1"]

Check if is prerelease version or not

if version.isPrerelease { ... }

Access the prerelease identifier via the preReleaseIdentifier Array

for identifier in version.preReleaseIdentifier
{
    // ...
}

Access the build metadata identifier via the buildMetadataIdentifier Array

for identifier in version.buildMetadataIdentifier
{
    // ...
}

Conforms to Printable so you can simply get a String representation by accessing the description property

print(version)
// OR
let stringRepresentation = version.description

mutability / immutability

Comparison

The default operators for comparison are implemented < , <= , > ,>= ,== , != This will compare major, minor, patch and the prerelease identifiers according to the Semantic Versioning Specification 2.0.0

Parser

The implementation includes a full-fledged component of parse String representation of a version. Please have a look at the tests and the source of SemanticVersioningParser for now 😉

Tests

The library includes a suite of tests showing how to use the different initialiser and the Parser

Extensions

There are some build in extensions to make your live easier.

NSBundle

You can get the version as struct Version of a NSBundle if set in the bunlde info.plist like:

let bundle = NSBundle(forClass: self.dynamicType)
if let version = bundle.version
{
	// ...
}

IntegerLiteralConvertible

Converts an Integer to a Version struct. You can use this only to represent major versions.

Custom extensions

Create your own extensions or Version representations by creating struct / object that conforms to SemanticVersion. Have a look at the extensions or the Version implementation for more information.

About

Semantic Versioning implementation in Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •