我试图从一个NSDictionary
NSNumber
s作为关键获取和设置。我想我正在根据这个答案https://stackoverflow.com/a/6891489/194309做的事情,但我的代码下面返回空值。我怎么能从一个NSDictionary int的关键是NSNumbers
- (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]]);
}
我希望在日志中to see well: well
而是我看我不想要什么:
to see well: (null)
与int
开始,我怎么能叫objectForKey
从NSDictionary
,其中键是NSNumber
小号?
(我最终想[sender tag]
作为元键提取从NSDictionary
值)
令人震惊的指控!!! –
好消息:我也错误地声明tagOfVideoKeys,所以修复只是切换接收新构建的NSDictionaries –