- 可以把基本数据类型转换成为对象
- Creating an NSNumber Object
- + numberWithBool:
- + numberWithChar:
- + numberWithDouble:
- + numberWithFloat:
- + numberWithInt:
- + numberWithInteger:
- + numberWithLong:
- + numberWithLongLong:
- + numberWithShort:
- + numberWithUnsignedChar:
- + numberWithUnsignedInt:
- + numberWithUnsignedInteger:
- + numberWithUnsignedLong:
- + numberWithUnsignedLongLong:
- + numberWithUnsignedShort:
- 例如我们要把一个整型的数据转化成为一个对象,并且存储到数组中。
- 首先我们定义一个数组:
NSMutableArray *arry = [NSMutableArray array];
NSNumber * num = [NSNumber numberWithInt:a];
[arry addObject:num];//把其存到数组中
//把对象还原成值
int a1 =[num intValue];
NSLog(@"a1 = %d",a1);
运行结果: