1.基本数据类型不是对象,所以不能向它们发消息,在cocoa中,集合只能存放对象,不能存放基本数据。spa
2.对象
//数字对象的初始化it
//类方法建立数字对象数据类型
NSNumber * intNumber = [NSNumber numberWithInt:10];float
/*int a = 10;方法
NSNumber * intNumber = [[NSNumber alloc] initWithInt:a];与上面的等价cocoa
*/数据
NSNumber * boolNumber = [NSNumber numberWithBool: YES];集合
//这里的intNumber,boolNumber都是对象,要用%@co
NSLog(@"intNumber is %@",intNumber);
NSLog(@"boolNumber is %@",boolNumber);
//实力方法建立数字对象
NSNumber *piNumber = [[NSNumber alloc] initWithFloat:3.14];
NSNumber *charNumber = [[NSNumber alloc] initWithChar:'a'];
NSLog(@"piNumber is %@",piNumber);
NSLog(@"charNumber is %@",charNumber);
//数字对象的转换
//还原成基本数据类型
int number = [intNumber intValue];
BOOL isBool = [boolNumber boolValue];
float pi = [piNumber floatValue];
char ch = [charNumber charValue];
NSLog(@"%d",number);
NSLog(@"%d",isBool);
NSLog(@"%.2f",pi);
NSLog(@"%c",ch);