以下代码段:
NSLog(@"userInfo: The timer is %d", timerCounter);
NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:timerCounter] forKey:@"timerCounter"];
NSUInteger c = (NSUInteger)[dict objectForKey:@"timerCounter"];
NSLog(@"userInfo: Timer started on %d", c);
Run Code Online (Sandbox Code Playgroud)
按以下方式产生输出:
2009-10-22 00:36:55.927 TimerHacking[2457:20b] userInfo: The timer is 1
2009-10-22 00:36:55.928 TimerHacking[2457:20b] userInfo: Timer started on 5295968
Run Code Online (Sandbox Code Playgroud)
(FWIW,timerCounter是一个NSUInteger.)
我确定我错过了一些相当明显的东西,只是不确定它是什么.
epa*_*tel 23
您应该使用intValue收到的对象(an NSNumber),而不是使用强制转换:
NSUInteger c = [[dict objectForKey:@"timerCounter"] intValue];
Run Code Online (Sandbox Code Playgroud)
Chu*_*uck 11
字典总是存储对象.NSInteger和NSUInteger不是对象.你的字典存储一个NSNumber(记得[NSNumber numberWithInteger:timerCounter]吗?),这是一个对象.正如epatel所说,unsignedIntegerValue如果你想要一个NSUInteger ,你需要询问NSNumber .
| 归档时间: |
|
| 查看次数: |
22164 次 |
| 最近记录: |