David Cordero

iOS and tvOS developer at @Zattoo. Amateur Triathlete. Passionate about coding and lifelong learning.

SwiftyVersion

29 Jun 2014 » swift, ios

SwiftyVersion A simpler way to manage Versions in Swift

Initialization

Using the default separator (which is a single point)

let myVersion = Version("1.5.2")

Or using a different separator

let myVersion = Version("1-5-1", usingSeparator: "-")

Logic Operator

Version supports the ==, >, <, <=, and >= operators

Example

let myVersion1 = Version("1-5-2", usingSeparator: "-")
let myVersion2 = Version("1.5.2.1")

print(myVersion1 == myVersion2) // "false"
print(myVersion1 > myVersion2)  // "false"
print(myVersion1 >= myVersion2) // "false"
print(myVersion1 < myVersion2)  // "true"
print(myVersion1 <= myVersion2) // "true"