0

I would like to have a Dictionary whose key type is a class type. Dictionaries require their keys to be Hashable.

In my case, the instances of that class type compare equal if they are reference-equal (they share their memory location). Is there a way that I can implement the Hashable protocol's hashValue based on the object's memory address?

In Swift 2, this could be done by using Unmanaged.toOpaque, however that method is gone in the first Swift 3 preview.

zneak
  • 134,922
  • 42
  • 253
  • 328
  • `Unmanaged.toOpaque()` would be `OpaquePointer(bitPattern: Unmanaged.passUnretained(self))` in Swift 3, but `unsafeAddress(of: self)` is simpler. – Martin R Jun 17 '16 at 05:27
  • Thank you. The other question didn't come up when I Googled it ("reference" and "key" being pretty generic search terms). – zneak Jun 17 '16 at 05:28

0 Answers0