Poniższy fragment kodu:Jak poprawnie ustawić wartość całkowitą w 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);
produkuje wyjście wzdłuż linii: (. FWIW, timerCounter jest 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
jestem pewien, że jestem brakuje czegoś dość oczywiste, po prostu nie jestem pewien co to jest.
W rzeczywistości, dla NSUInteger, powinieneś użyć '-unsignedIntegerValue'. –
(I '+ [NSNumber numberWithUnsignedInteger:]', aby utworzyć NSNumber, jeśli rzeczywiście ma on być unsigned.) – Wevah
Możesz użyć '@ (timerCounter)' zamiast '[NSNumber numberWithInteger: timerCounter]' – fpg1503