Created
July 3, 2019 09:17
-
-
Save mrpcalcantara/8dd3c54ef66a067e30dedd4c5e94302c to your computer and use it in GitHub Desktop.
Comparing enums
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
// Taken from https://stackoverflow.com/a/55409389 | |
public protocol RawComparable : Comparable where Self : RawRepresentable, RawValue: Comparable { } | |
extension RawComparable { | |
public static func < (lhs: Self, rhs: Self) -> Bool { | |
return lhs.rawValue < rhs.rawValue | |
} | |
} | |
enum TestEnum: Int, RawComparable { | |
case value1 | |
case value2 | |
case value3 | |
} | |
func checkCompare(val1: TestEnum, val2: TestEnum) -> Bool { | |
return val1 < val2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment