I’m trying to get and set from an NSDictionary with NSNumbers as the keys. I think I’m doing things according to this answer https://stackoverflow.com/a/6891489/194309 but my code below returns null values.
- (void)viewDidLoad {
[super viewDidLoad];
NSInteger const SET1 = 1;
NSInteger const SET2 = 2;
videoKeyOfTag = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:SET1], @"well",
[NSNumber numberWithInt:SET2], @"great",
nil];
NSLog(@"to see well: %@",[videoKeyOfTag objectForKey:[NSNumber numberWithInt:SET1]]);
}
I expect to see well: well in the log but instead I see what I don’t want:
to see well: (null)
Starting with an int, how can I call objectForKey from an NSDictionary where the keys are NSNumbers?
(I eventually want to extract values from the NSDictionary with [sender tag] as the meta-key.)
If you want the numbers to be keys, you need to invert the order in the constructor: