NSMutableArray中存放struct变量的方法

如何将一个struct结构体变量存放到NSMutableArray中呢?与将数值型变量类似,不过这次是将其转换为NSValue对象。 假设结构体:
struct testStruct {
 int value1;
 int value2;
 };
存入的代码
struct testStruct t;
 t.value1=1;
 t.value2=2;
 //将struct对象装入到NSArray中
 [testArray addObject:[NSValue value:&t withObjCType:@encode(struct testStruct)]];
取出的代码
struct testStruct p;
 [[testArray objectAtIndex:0] getValue:&p];
   

posted on 2012-11-24 12:02  流れ星ーー  阅读(236)  评论(0编辑  收藏  举报

导航