2013年9月22日星期日

[Android] How to add a struct to NSMutableArray in

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
the following error:


how to solve ? Hope the exhibitions !
------ Solution ---------------------------------------- ----
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;
};
deposit code
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];
------ eference ----------------- ----------------------
find their own answers , and paste it on their own knot 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 /

没有评论:

发表评论