os开发之封装自定义的结构体对象,CGRect,CGSize常用结构体基本使用

来源:互联网 发布:淘宝运营视频下载 编辑:程序博客网 时间:2024/06/06 02:13

方法如下:

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];
0 0
原创粉丝点击