NSValue

作者: 至于么_ni | 来源:发表于2018-01-08 10:49 被阅读0次

    #import <Foundation/Foundation.h>

    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

          本文链接:https://www.haomeiwen.com/subject/fbesnxtx.html