I was working on a utility class and was playing with the idea of using the
id of an object (e.g.
NSObject) as a key in
NSDictionary. Setting it directly doesn’t work though:
NSObject *obj = [[[NSObject alloc] init] autorelease]; // we'll use this as the key NSMutableDictionary *dict = [[[NSMutableDictionary alloc] init] autorelease]; [dict setObject:@"a value" forKey:obj]; // won't work