Component/s: Standard Library
Checked with both
Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
I have a Swift class below. When I insert its 2 equal instances into a Swift Set upon insertion Hashable protocol implementation is used as expected. However when I insert the same instances into NSMutableSet none of the implementations (Hashable or NSObjectProtocol methods) are used.
When I disassemble the code, as I see _SwiftObject_hash method is called. But it just returns object address, so identity is used for duplicate checking.
When I change the class type to a Swift struct or a class that inherits NSObject everything works as expected.
I'm not sure if this is expected behavior. But if it's that's really confusing. It caused a bug in my project and cost me one day of debugging, trying alternatives etc. After searching for a while I couldn't find any resource referencing this behavior, so here is a bug report.