星空网 > 软件开发 > 操作系统

NSValueNSNumber

void testForNSValue(void)

{

    int i=10;

    

//    NSLog(@"encode(int)=%s",@encode(int));

//    NSLog(@"encode(float)=%s",@encode(float));

//    NSLog(@"encode(struct student)=%s",@encode(struct student));

    NSValue* value =[[NSValue alloc]initWithBytes:&i objCType:@encode(int) ];

    

    int ret;

    [value getValue:&ret];

    NSLog(@"ret=%i",ret);

 

 

    struct s stt={88,99};

    NSValue* value2 =[[ NSValue alloc]initWithBytes:&stt objCType:@encode(struct s)];

    

    struct s newStt;

    [value2 getValue:&newStt];

    NSLog(@"newStt.a=%i, newStt.b=%i",newStt.a,newStt.b);

    

    NSLog(@"objCType is %s", [value2 objCType]);

//    @encode(struct s) == [value2 objCType]

 

    int *p=&i;

    NSLog(@"p=%p",p);

    NSValue* v3 = [[ NSValue alloc]initWithBytes:&p objCType:@encode(int *)];

    int *q;

    [v3 getValue:&q];

    NSLog(@"q=%p",q);

    

 

}

 

void testNSNumber(void)

{

    //对4字节有符号整型

    NSNumber *obj1 = [ NSNumber numberWithInt:123];

    

    NSLog(@"obj1 is %i",[obj1 intValue]);

 

    //对8字节有符号整型

    NSNumber *obj2 = [ NSNumber numberWithInteger:88888888];

    NSLog(@"obj2 is %li", [obj2 integerValue]);

 

    //对4字节无符号整型

    NSNumber * obj3 = [ NSNumber numberWithUnsignedInt:345];

    NSLog(@"obj3 is %u", [obj3 unsignedIntValue]);

    

    //对8字节无符号整型

    NSNumber* obj4 = [ NSNumber numberWithUnsignedInteger:99999999];

    NSLog(@"obj4 is %lu", [obj4 unsignedIntegerValue]);

 

    //其它的基本数据类型的封装方法

//    NSNumber numberWithUnsignedChar:<#(unsigned char)#>

//    obj4 unsignedCharValue

    

//    NSNumber numberWithShort:<#(short)#>

//      obj4 shortValue

    

//     NSNumber numberWithUnsignedLongLong:<#(unsigned long long)#>

//     obj4 unsignedLongLongValue

    

    NSNumber* obj5 = [ NSNumber numberWithBool:YES];

    NSLog(@"obj5 is %i",[obj5 boolValue]);

    

    int a;

    NSNumber * obj6 = [NSNumber numberWithUnsignedLong:(unsigned long)&a];

    int * add =  (int *)[obj6 unsignedLongValue];

}




原标题:NSValueNSNumber

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

东南亚电商双雄竞争激烈,Lazada增长速度稍逊一筹:https://www.goluckyvip.com/news/3477.html
第一次经历旺季就神操作,新锐3C卖家这招“绝杀”东南亚:https://www.goluckyvip.com/news/3478.html
东南亚电商之争胜负已分,Lazada首次数据披露:https://www.goluckyvip.com/news/3479.html
加拿大出台新规,海运整箱货物出EBL或者SWB或将失去货物控制权:https://www.goluckyvip.com/news/348.html
Shopee大件渠道订单未在规定时间内入仓,将被取消:https://www.goluckyvip.com/news/3480.html
法国物流商Asendia:https://www.goluckyvip.com/news/3481.html
三亚有哪些酒店值得入住?:https://www.vstour.cn/a/366173.html
零售晚报:丽人丽妆2023年扭亏为盈 玉容初、美壹堂等自有品牌增速超40% :https://www.kjdsnews.com/a/1836649.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流