枚举综合一致性

Posted by Genie on July 30, 2020
1
2
3
4
5
6
7
8
9
10
11
12
13
14
enum Priority: Int, Comparable {
    case low
    case medium
    case high
    
    static func < (lhs: Self, rhs: Self) -> Bool {
        return lhs.rawValue < rhs.rawValue
    }
}

print(Priority.medium < .high)
print(Priority.low > .medium)
print(Priority.low < .medium)