Why get wrong hashValue from Enum from Xcode 10? Is it Apple's bug?

286 views Asked by At

Update:

I met this problem because I use the hashValue for get Enum count as Antonio's suggestion in this question.

And also, Antonio's answer works well before Xcode 10, I just want to know why the result is changed now.


Original question

Environment: macOS 10.14.1

The same enum, the Xcode 10.1 return the enum item's hashValue as 4607296766572878277, the Xcode 9.4.1 returns 0:

Code:

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: enter image description here

Xcode 9.4.1: enter image description here

Is this Apple's bug?

1

There are 1 answers

0
Raymond Liao On BEST ANSWER

Thanks for all guys's answer. As rmaddy's said the document as below: enter image description here

So do not use hashValue during a future execution.