In several places, I need object mappings to objects and used NSMutableDictionary as a lookup table. The key was placed in the hash code of NSObject, for example:
[dict setObject:newObject forKey:[NSNumber numberWithUnsignedInt:[keyObject hash]]];
where keyObject is an instance of a user class that inherits the implementation of the hash function NSObject - (NSUInteger) as-is. I saved the keyObject references elsewhere, which I can use to get newObject:
[dict objectForKey:[NSNumber numberWithUnsignedInt:[keyObject hash]]]
This seems to work so far, although the corresponding application is still young.
Matt Gallagher, however, writes about this approach:
(don't laugh, I saw it)
which undermines my confidence a bit (and since this is for an iOS application, I cannot use it suggested by NSMapTable).
- , NSObject , iOS?
, unsigned int, , , -hash, , .
unsigned int
-hash
, NSNumber, , NSValue +valueWithPointer: -pointerValue.
NSNumber
NSValue
+valueWithPointer:
-pointerValue
NSDictionary NSMapTable - , Core Foundation , , . , , , ; , , , , , , - .
NSDictionary
NSMapTable
.