I am storing an object’s hash value as a unique identifier within that object like so:
[myObj setValue:[NSNumber numberWithInt:[myObj hash]] forKey:@"ID"];
But when retrieving the value for that key, the value is no longer consistent with the hash, to wit this code:
NSLog(@"[myObj hash] %i",[myObj hash]);
NSLog(@"[myObj hash] NSNumber %@",[NSNumber numberWithInt:[myObj hash]]);
[myObj setValue:[NSNumber numberWithInt:[myObj hash]] forKey:@"ID"];
NSLog(@"myObj ID %@",[myObj valueForKey:@"ID"]);
Produces output similar to:
[myObj hash] -976941568
[myObj hash] NSNumber -976941568
myObj ID 3584
What basic things about hash and/or key/value pairs do I clearly not understand?
Thompson
[EDIT]
Pardon my newbie manners! myObj is a NSManagedObject, and is key/value compliant, so ID is simply a key I create on the fly.
The hash method returns an unsigned integer, try this instead