I'm trying to create an NSDictionary that stores objects with keys based on IDs. I know I can use NSNumber objects, but why can't I just use an int instead? Is there some class that supports this? Something like an NSSet almost works, except I can't access it by it's hash value (I've overridden - (NSUInteger) hash
to return the object's ID, which always unique)
I'm basically trying to turn this:
//objects is an NSMutableDictionary
- (id) objectForId:(NSUInteger)id {
return [objects objectForKey:[NSNumber numberWithInt:id]];
}
- (void) addObject:(Object *)foo {
[objects setObject:foo forKey:[NSNumber numberWithInt:id]];
}
into this:
//objects is an NSSet
- (id) objectForId:(NSUInteger)id {
return [objects objectForHash:id];
}
- (void) addObject:(Object *)foo {
[objects addObject:foo];
}