NSNumber
#import <Foundation/Foundation.h>
int main()
{
// @20 将 20包装成一个NSNumber对像
NSArray *array = @[
@{@"name" : @"jack", @"age" : @20},
@{@"name" : @"rose", @"age" : @25},
@{@"name" : @"jim", @"age" : @27}
];
// 将各种基本数据类型包装成NSNumber对象
@10.5;
@YES;
@'A'; // NSNumber对象
@"A"; // NSString对象
// 将age变量包装成NSNumber对象
int age = 100;
@(age);
//[NSNumber numberWithInt:age];
NSNumber *n = [NSNumber numberWithDouble:10.5];
int d = [n doubleValue];
int a = 20;
// @"20"
NSString *str = [NSString stringWithFormat:@"%d", a];
NSLog(@"%d", [str intValue]);
return 0;
}
void test()
{
NSNumber *num = [NSNumber numberWithInt:10];
NSDictionary *dict = @{
@"name" : @"jack",
@"age" : num
};
NSNumber *num2 = dict[@"age"];
int a = [num2 intValue];
NSLog(@"%d" , a);
}