Convert NSNumber to int in Objective-C
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];
A tested one-liner:
int number = ((NSNumber*)[dict objectForKey:@"integer"]).intValue;
Use the NSNumber method intValue
Here is Apple reference documentation