iOS开发-封装自定义的结构体对象

来源:互联网 发布:声卡软件手机版 编辑:程序博客网 时间:2024/06/05 09:34

ios 中如何使用oc封装一个 结构体到  NSValue中呢?

方法如下:

typedef  struct{  //自定义一个结构体    int age;    int number;}Student;NSValue *stu=[NSValue valueWithBytes:&stu objCtype :@encode(Student)];//把结构体封装成一个对象Student  value2;//定义一个结构体变量来接受从NSValue得到的结构体[stu getValue:&value2];//把 stu对象中的结构体取出来int a=value2.age;  //取得结构体中的字段其他,系统自带的CGPoint p=[value  CGPointValue];
系统自带的创建 NSValue 和  获取 CG结构体值的方法
    NSValue *v=[NSValue valueWithCGRect:CGRectMake(0, 0, 0, 0)];    CGRect rect=[v CGRectValue];    NSValue *v2=[NSValue valueWithCGSize:CGSizeZero];    CGSize size=[v2 CGSizeValue];    NSValue *v3=[NSValue valueWithCGPoint:CGPointMake(0, 0)];    CGPoint p=[v3 CGPointValue];
原文地址:http://blog.csdn.net/yangbingbinga/article/details/43114469

0 0
原创粉丝点击