标签:ios自定义结构体对象 nsvalue 自定义的结构体
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/43114469ios开发之封装自定义的结构体对象,CGRect,CGSize常用结构体基本使用
标签:ios自定义结构体对象 nsvalue 自定义的结构体
原文地址:http://blog.csdn.net/yangbingbinga/article/details/43114469