typedef struct
{
CGFloat r;
CGFloat g;
CGFloat b;
}TestStruct;
NSMutableArray *array = [NSMutableArray array];
//保存
for (unsigned i = 0 ; i<5; i++) {
TestStruct s;
s.b = i;
s.g = 1.0;
s.r = 2.0f;
NSValue *value = nil;
value = [NSValue valueWithBytes:&s objCType:@encode(TestStruct)];
[array addObject:value];
}
//读取
for (NSValue *value in array) {
TestStruct s ;
[value getValue:&s];
NSLog(@"%f",s.b);
}
网友评论