NSValue
2015-06-04 22:11
447 查看
针对结构体
NSNumber->数字
NSNumber是NSValue的一个子类
NSValue可以包装任意值(也可以包装对象,吃太多 )
void value(){
CGPoint point=CGPointMake(10,10);
NSValue *value=[NSValue valueWithPoint:point];
NSMutableArray array=[NSMutableArray array];
[array addObject:value];
NSValue *value1=[array lastObject];
CGPoint point1=[value1 pointValue];
BOOL result=CGPointEqualToPoint(point1,point);
NSLog(@”result=%i”,result);
}
typedef struct{
int year;
int month;
int day;
}Date;
void value2(){
Date date={2015,6,4};
//void * 代表任何指针
//根绝结构体类型生成对应的字符串
char *type=@encode(date);
NSValue *value=[NSValue value:&date withObjCType:type];
//取出包装好的结构体
//定义一个结构体变量用于接收
//[value objCType]; 取出类型描述字符串
Date date1;
[value getValue:&date];//没有返回值,指针搞了
NSLog(@“year=%i,month=%i,day=%i”,date1.year,date1.month,date1.day);
}
NSNumber->数字
NSNumber是NSValue的一个子类
NSValue可以包装任意值(也可以包装对象,吃太多 )
void value(){
CGPoint point=CGPointMake(10,10);
NSValue *value=[NSValue valueWithPoint:point];
NSMutableArray array=[NSMutableArray array];
[array addObject:value];
NSValue *value1=[array lastObject];
CGPoint point1=[value1 pointValue];
BOOL result=CGPointEqualToPoint(point1,point);
NSLog(@”result=%i”,result);
}
typedef struct{
int year;
int month;
int day;
}Date;
void value2(){
Date date={2015,6,4};
//void * 代表任何指针
//根绝结构体类型生成对应的字符串
char *type=@encode(date);
NSValue *value=[NSValue value:&date withObjCType:type];
//取出包装好的结构体
//定义一个结构体变量用于接收
//[value objCType]; 取出类型描述字符串
Date date1;
[value getValue:&date];//没有返回值,指针搞了
NSLog(@“year=%i,month=%i,day=%i”,date1.year,date1.month,date1.day);
}
相关文章推荐
- 人机交互设计——“搜狗输入法”分析
- UIImageView 基本用法
- easyui提交表单数据的时候如何防止二次提交
- Ueditor结合七牛云及百度云存储(JAVA版,ueditor-1.4.3)实现图片文件上传
- STL之deque
- UIScrollView
- UITableView固定表头
- STL --> queue单向队列
- [UI] 精美UI界面欣赏[10]
- STL --> deque双向队列
- UIScrollView使用注意
- 向量空间模型实现文档查询(Vector Space Model to realize document query)
- 【easyui】--普通js中获取easyui中分页信息(page,pageSize等)
- 【easyui】--combobox--赋值和获取选中的值
- 【Distinct Subsequences】cpp
- HDU 4584 Building bridges
- Arduino学习笔记之Arduino的数字输出&串口输入
- UITableView_4cell简单练习,汽车品牌展示
- UIAlertView的基本使用和对话框中按钮的事件处理方法
- 多线程NSInvocation+队列NSOperationQueue+NSBlockOperation