基本數(shù)據類型:
int long NSInteger
float double
BOOl
由于不是對象類型垛耳,所以OC中的數(shù)組和字典都不能保存
NSNumber -> 將任意基本數(shù)據類型封裝成對象類型
//1.創(chuàng)建
//基本數(shù)據類型 ===> 對象
//空
NSNumber *number = [[NSNumber alloc]init];
//int
NSNumber *int_ = [[NSNumber alloc]initWithInt:10];
//float
NSNumber *float_ = [[NSNumber alloc]initWithFloat:3.14];
//double
NSNumber *double_ = [[NSNumber alloc]initWithDouble:3.14];
//BOOL
NSNumber *bool_ [[NSNumber alloc]initWithBool:YES];
//char
NSNumber *char_ = [[NSNumber alloc]initWithChar:'C'];
NSLog(@"%@",int_);
//2.快速創(chuàng)建:@...
NSNumber *_int = @100;
NSNumber *_float = @3.14;
NSNumber *_bool = @YES;
NSNumber *_char = @'c';
NSNumber *_double = @(3.14 * 6 + 2.5);
//3.NSNuber可以放入容器中
NSArray *array = @[_int,_float,_bool,_char];
NSDictionary *dic = @{@"key1":_int,@"key2":_double};
//4.NSNumber ==>基本數(shù)據類型
int a = [_int intValue];
float b = [_float floatValue];
char c = [_char charValue];
double = [_double doubleValue]