Have a look at the documentation. Use the intValue
method:
NSNumber *number = [dict objectForKey:@"integer"];
int intValue = [number intValue];
You should stick to the NSInteger
data types when possible. So you'd create the number like that:
NSInteger myValue = 1;
NSNumber *number = [NSNumber numberWithInteger: myValue];
Decoding works with the integerValue
method then:
NSInteger value = [number integerValue];
Use the NSNumber method intValue
Here is Apple reference documentation
A tested one-liner:
int number = ((NSNumber*)[dict objectForKey:@"integer"]).intValue;
A less verbose approach:
int number = [dict[@"integer"] intValue];
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