-5

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?

Raymond Liao
  • 1,799
  • 3
  • 20
  • 32
  • 6
    Please post actual code and not images of code. – l'L'l Nov 07 '18 at 06:08
  • 8
    Why do you expect the hash value to be the same? From the documentation for `hashValue`: *"Hash values are not guaranteed to be equal across different executions of your program. Do not save hash values to use during a future execution."* – rmaddy Nov 07 '18 at 06:11
  • 1
    Related: [Is it sensible to rely on hashValue for enum cases?](https://stackoverflow.com/questions/51266779/is-it-sensible-to-rely-on-hashvalue-for-enum-cases?s=4|42.1422) – rmaddy Nov 07 '18 at 06:14
  • Better this one: https://stackoverflow.com/questions/51205254/xcode-9-and-xcode-10-giving-different-results-even-with-same-swift-version (which is in comment of the linked question). It changed, but question is what do you want to do with it, and why should it be the same? – Larme Nov 07 '18 at 09:16
  • Possible duplicate of [Xcode 9 and Xcode 10 giving different results, even with same swift version](https://stackoverflow.com/questions/51205254/xcode-9-and-xcode-10-giving-different-results-even-with-same-swift-version) – Dávid Pásztor Nov 07 '18 at 09:30
  • I've updated my question. – Raymond Liao Nov 08 '18 at 05:47
  • Check my answer to get indexValue on following link https://stackoverflow.com/a/54548695/6808061 – Amit Gajjar Feb 06 '19 at 07:47

1 Answers1

0

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.

Raymond Liao
  • 1,799
  • 3
  • 20
  • 32