Monday, September 23, 2013

How to add a NSMutableArray to a struct

ARC project, define a struct structure, as
struct data1 {
__unsafe_unretained NSString * name;
__unsafe_unretained NSString * telephone;
__unsafe_unretained NSString * birthday;
__unsafe_unretained NSString * QQ;
__unsafe_unretained NSString * homepage;

} D;

And a variable array @ property (retain, nonatomic) NSMutableArray * temp;
Now, I want to join the D structure variable array temp in,


Reply:
Themselves to find the answer
http://iphone.xiaoxiaostudio.net/2012/11/24/nsmutablearray% E4% B8% AD% E5% AD% 98% E6% 94% BEstruct% E5% 8F% 98% E9% 87% 8F% E7% 9A% 84% E6% 96% B9% E6% B3% 95 /

Reply:
How to structure a struct variable into NSMutableArray in it? Similar with the numerical variables, but this is to convert it to NSValue object.
Assuming structure:
struct testStruct {
int value1;
int value2;
};
The code stored in
struct testStruct t;
t.value1 = 1;
t.value2 = 2;
/ / Struct object will be loaded into the NSArray in
[TestArray addObject: [NSValue value: & t withObjCType: @ encode (struct testStruct)]];
Extracted code
struct testStruct p;
[[TestArray objectAtIndex: 0] getValue: & p];

No comments:

Post a Comment