0

Say I have an arbitrary Objective-C, NSObject subclass (from a library) that I want to use as a dictionary key.

If I try to insert another object into the dictionary as a key, it overwrites that first object. Seemingly it's deciding the keys are equal.

How does the Swift dictionary decide this? The hash method on the Objective-C NSObject subclass? Or is it isEqualTo?

Doug Smith
  • 29,668
  • 57
  • 204
  • 388
  • 1
    Why not override both `isEqual` and `hash` in your Objective-C class and see which is called as you try to use it in either a Swift or Objective-C dictionary. Then you'll have your answer. But you can be sure that the check is whether the two keys are equal or not that matters. – rmaddy Apr 06 '19 at 00:00
  • Possible duplicate of [NSObject subclass in Swift: hash vs hashValue, isEqual vs ==](https://stackoverflow.com/questions/33319959/nsobject-subclass-in-swift-hash-vs-hashvalue-isequal-vs) – Coder-256 Apr 06 '19 at 02:23

0 Answers0