NSValue

#import

typedef struct{

    int x;

    int y;

}TRPoint;

typedef struct{

    char ch;

    double d;

}TRMyData;

int main(int argc, const char * argv[]){

    @autoreleasepool{

        TRPoint p;

        p.x = 10;

        p.y = 15;

        NSLog(@"%d%d",p.x,p.y); //  1015

        NSValue * value = [NSValue valueWithBytes:&p objCType:@encode(TRPoint)];//封装

        NSLog(@"%@",value);      //  <0a000000 0f000000>


        TRPoint p1;

        [value getValue:&p1]; //拆封

        NSLog(@"(%d,%d)", p1.x, p1.y); //  (10,15)


        TRMyData dara = {'a', 3.14};

        NSValue * md = [NSValue valueWithBytes:&data objCType:@encode(TRMyData)];

        TRMyData data1;

        [mdgetValue:&data1];

    }

    return 0;

}

你可能感兴趣的:(NSValue)