Foundation Hashing
TIL NSData only uses the first 80 bytes to hash itself and doesn’t use length at all for some reason.
Other classes with potentially bad hash codes: NSArray
and NSDictionary
both simply return their count. NSString’s hashing has changed a few times. Currently it uses up to 96 characters (taken from the beginning, middle, and end) and also incorporates the length.
If you know these hash functions are bad for your data, you can use wrapper objects to override the -hash
method or an NSMapTable with a custom NSPointerFunctions.
Previously: Swift Tuples Aren’t Equatable.
Update (2016-08-25): David Smith:
Using the length is a good idea. We [should] change that.
Just an oversight afaik. Not all that many people hitting that code path. Should be a safe fix.