作用
NSValue可以对结构体进行封装,NSValue是NSNumber的父类
NSRange rang = {10,20};
//封包
NSValue *rangValue = [NSValue valueWithRange:rang];
NSRange rang2 = [rangValue rangeValue];
NSLog(@"(%ld,%ld)",rang2.location,rang2.length);
对自定义的结构体封包
struct WXPoint
{
float x;
float y;
};
struct WXPoint p = {50,100};
NSValue *pointValue = [NSValue value:&p withObjcType:@encode(struct WXPoint)];
对自定义的结构体解包
struct WXPoint p2;
[pointValue getValue:&p2];
NSLog(@"p2.x=%f,p2.y=%f",p2.x,p2.y); |
|