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];