-----------android培训、java培训、java学习型技术博客、期待与您交流!------------
-----------并不是生来就是大神、代码量决定一切、其他都是假象、-----------
//这些包装的数字,返回值就是NSNumber
int a = 10;
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"jack",@"name",@(a),@"age", nil];
//@(a) = 10; 也就是说 直接打印NSNumber对象 可以得到它的值
//2.NSNumber对象中的基本数据类型
// -(char)charValue; -(int)intcharValue,-(long)longcharValue,-(double)doublecharValue,-(BOOL)boolcharValue
//-(NSString *)NSStringcharValue,-(NSComparisonResult)compare:(NSNumber *)otherNumber:other,-[(BOOL)isEqualToNumber:(NSNumber*)number
//如
//创建一个int类型的NSNumber对象
NSNumber *n1 = @10;
//将n1对象的值传给int b
int b = [n1 intValue];
NSLog(@"%d",b);
//记录点
int i = 10;
NSNumber *num = [NSNumber numberWithInt:10];//创建Number对象
NSNumber *n = @12;//快速创建
NSMutableDictionary *d = [NSMutableDictionary dictionaryWithObject:num forKey:@"age"];//导入数组
NSDictionary *d1 = [NSDictionary dictionaryWithObject:@20 forKey:@"age"];//快速包装
NSLog(@"%@",d[@"age"]);
//or
NSDictionary *ary = @{@"age" : @20};
NSLog(@"%@",ary[@"age"]);
//3类型转换
NSNumber *m = @12;
int a1 = [m intValue];
int a2 = [@12 intValue];
NSLog(@"%d",a2);
NSValue 用来包装 Size Point Rect surest 等 因为想着中结构体也是不能导入数组或者字典中的 需要包装一下才能导入//练习点
NSSize size = CGSizeMake(100, 50);//包装size类型
NSPoint p = CGPointMake(0, 0);
NSRect rect = CGRectMake(0, 0, 100, 50);
NSValue *val = [NSValue valueWithBytes:&size objCType:@encode(NSSize)];
NSValue *val1 = [NSValue valueWithBytes:&p objCType:@encode(NSPoint) ];
NSDictionary *dict = [NSDictionary dictionaryWithObject:val forKey:@"xy"];
NSLog(@"%@",dict[@"xy"]);
NSDictionary *dict1 = [NSDictionary dictionaryWithObjectsAndKeys:val1,@"point",val,@"size", nil];
NSLog(@"%@",dict1[@"size"]);
NSValue *val2 = [NSValue valueWithRect:rect];
NSDictionary *dict2 = @{@"point" : val1 , @"size" : val , @"rect" : val2};
NSLog(@"%@",dict2[@"size"]);
//NSValue 练习点
typedef struct {
int year;
int month;
int day;
}Date;
Date lulu = {1983,1,29};
NSValue *birthday = [NSValue valueWithBytes:&lulu3 objCType:@encode(Date) ];
NSDictionary *dict = @{@"name" : @"lulu" , @"qq" : @"982580186" , @"age" : @32 , @"home" : @"china" , @"sex" : @"Man",@"birthday" : lulu3};
Date lulu2;
[birthday getValue:&lulu2];
NSLog(@"%d,%d,%d",lulu2.year,lulu2.month,lulu2.day);