我試圖從一個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 –