更新:
我遇到了这个问题,因为我使用 hashValue 来获取枚举计数作为 Antonio在这个问题中的建议。
而且,Antonio 的答案在 Xcode 10 之前效果很好,我只想知道为什么现在结果会改变。
原始问题
环境:macOS 10.14.1
同样的枚举,Xcode 10.1 返回枚举项的 hashValue 为 4607296766572878277,Xcode 9.4.1 返回 0:
代码:
enum IntEnum: Int {
case first = 1, second
}
let x = IntEnum.first.hashValue
print("first hashValue \(x)")
enum strEnum: String {
case first, second
}
let a = strEnum.first.hashValue
这是苹果的bug吗?