The following is returning an error because evidently I cannot compare an NSInteger or int to nil. Can anyone suggest syntax to do this
NSInteger *lastID = [[NSUserDefaults standardUserDefaults] integerForKey:@"lastID"]==nil ? @1 : [[NSUserDefaults standardUserDefaults] integerForKey:@"lastID"];
NSInteger lastID = [[NSUserDefaults standardUserDefaults] integerForKey:@"lastID"] == 0 ? 1 : [[NSUserDefaults standardUserDefaults] integerForKey:@"lastID"];
NSInteger is a primitive type. nil is for objects. 0
check, checks is your userDefaults' integer value assigned a value. If it didn't assigned, it returns 0.
NSInteger is a primitive type, not an object. I'm quite sure that an NSInteger* is not what you want, but an NSInteger. integerForKey returns an NSInteger, not an NSInteger*.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With