------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! -------
NSnumber
/*
将各种基本数据类型包装成NSNumber对象
@20
@10.5;
@YES;
@'A'; // NSNumber对象
将age变量包装成NSNumber对象
int age = 100;
@(age);
[NSNumber numberWithInt:age];
*/
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
NSNumber *num = [NSNumber numberWithInt:10];
NSDictionary *dict = @{
@"name" : @"rose",
@"age" : num,
};
NSLog(@"%@",dict[@"age"]);
NSNumber *num2 = dict[@"age"];
int a = [num2 intValue];
NSLog(@"%d",a);
return 0;
}
void test()
{
//@20 将20包装成一个NSNumber对象
NSArray *array = @[
@{@"name" : @"jack",@"age" : @20},
@{@"name" : @"rose", @"age" : @25},
@{@"name" : @"jim", @"age" : @27}
];
int age = 100;
@(age);
NSNumber *n = [NSNumber numberWithInt:age];
int d = [n intValue];
NSLog(@"%d",d);
int a = 20;
//@20
NSString *str = [NSString stringWithFormat:@"%d",a];
NSLog(@"%d",[str intValue]);
}