Đoạn mã sau:Làm thế nào để thiết lập đúng giá trị số nguyên trong NSDictionary?
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);
tạo ra dọc theo dòng: (. FWIW, timerCounter là một NSUInteger)
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
Tôi chắc rằng tôi đang thiếu một cái gì đó khá rõ ràng, chỉ cần không chắc chắn nó là gì.
Thực tế, đối với NSUInteger, bạn nên sử dụng '-unsignedIntegerValue'. –
(Và '+ [NSNumber numberWithUnsignedInteger:]' để tạo NSNumber, nếu nó thực sự có nghĩa là để được unsigned.) – Wevah
Bạn có thể sử dụng '@ (timerCounter)' thay vì '[NSNumber numberWithInteger: timerCounter]' – fpg1503