-5

更新:

我遇到了这个问题,因为我使用 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

Xcode 10.1: 在此处输入图像描述

Xcode 9.4.1: 在此处输入图像描述

这是苹果的bug吗?

4

1 回答 1

0

谢谢大家的回答。正如 rmaddy 所说,文件如下: 在此处输入图像描述

所以在以后的执行过程中不要使用 hashValue。

于 2018-11-08T06:02:03.227 回答