-
Notifications
You must be signed in to change notification settings - Fork 66
Description
I just happened to read this
Storing mutable objects in collection objects can cause problems. Certain collections can become invalid or even corrupt if objects they contain mutate because, by mutating, these objects can affect the way they are placed in the collection. First, the properties of objects that are keys in hashing collections such as
NSDictionaryobjects orNSSetobjects will, if changed, corrupt the collection if the changed properties affect the results of the object’shashorisEqual:methods. (If the hash method of the objects in the collection does not depend on their internal state, corruption is less likely.) Second, if an object in an ordered collection such as a sorted array has its properties changed, this might affect how the object compares to other objects in the array, thus rendering the ordering invalid.
Which is just... Ugh!
So yeah, we may need to manually define which types are safe to use as hash keys - though it might not be that bad, since you usually just want to use NSString or NSNumber anyways.