1. We all know that the data type that needs to be placed in the NSMutableArray variable array is a class, but the ordinary data type is not a class. We can use the NSNumber class to package it into a class (ie, implement it in the form of an object) for storage.
NSMutableArray *array = [[NSMutableArray alloc] init];
BOOL isYes = NO;
int a = 10;
long longA = 10;
double doubleA = 10.123;
char charStr = 'c';
[array addObject:[NSNumber numberWithBool:isYes]];
[array addObject:[NSNumber numberWithInt:a]];
[array addObject:[NSNumber numberWithDouble:doubleA]];
[array addObject:[NSNumber numberWithLong:longA]];
[array addObject:[NSNumber numberWithChar:charStr]];
After encapsulating the basic type data into NSNumber, you can retrieve it through the following instance method
- (char) charValue;
- (int) intValue;
- (float) floatValue;
- (BOOL) boolValue;
- (NSString *) stringValue;
2. Give a chestnut
例如 NSNumber *num = [NSNumber numberWithInt:100];
NSInteger integer = [num intValue];