Created
November 13, 2020 13:43
-
-
Save sayler8182/f0435cac02f43e9ae8558aeac8859331 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: Version | |
extension Version: Equatable, Comparable { | |
public func isEqual(_ version: Version?) -> Bool { | |
guard let version: String = version?.version else { return false } | |
return version.compare(self.version, options: String.CompareOptions.numeric) == .orderedSame | |
} | |
public func isGreater(_ version: Version?) -> Bool { | |
guard let version: String = version?.version else { return false } | |
return version.compare(self.version, options: String.CompareOptions.numeric) == .orderedAscending | |
} | |
public func isLower(_ version: Version?) -> Bool { | |
guard let version: String = version?.version else { return false } | |
return version.compare(self.version, options: String.CompareOptions.numeric) == .orderedDescending | |
} | |
public static func == (lhs: Version, rhs: Version) -> Bool { | |
return lhs.isEqual(rhs) | |
} | |
public static func < (lhs: Version, rhs: Version) -> Bool { | |
return lhs.isLower(rhs) | |
} | |
public static func > (lhs: Version, rhs: Version) -> Bool { | |
return lhs.isGreater(rhs) | |
} | |
public static func <= (lhs: Version, rhs: Version) -> Bool { | |
return lhs.isLower(rhs) || lhs.isEqual(rhs) | |
} | |
public static func >= (lhs: Version, rhs: Version) -> Bool { | |
return lhs.isGreater(rhs) || lhs.isEqual(rhs) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment