Save struct to NSDictionary
Save struct to NSDictionary
- Subject: Save struct to NSDictionary
- From: Lorenzo <email@hidden>
- Date: Thu, 15 Sep 2005 22:55:38 +0200
Hi,
I defined a simple struct like this
typedef struct
{
float x;
float y;
BOOL on;
}
XVector;
And I have an array of this struct: XVector xVectors[16];
I would like to transform xVectors[16] to a NSData object so I can put it
into a NSDictionary and save it together with the document file.
Actually I transform xVectors to a NSMutableArray then I add this array to
the document dictionary.
- (NSMutableArray*)GetXVector
{
NSMutableArray *vArray = [NSMutableArray array];
NSMutableDictionary *vDict;
int i, totVectors = 16;
for(i = 0; i < 16; i++){
vDict = [NSMutableDictionary dictionary];
[vDict setObject:[NSNumber numberWithFloat:xVectors[i].x] forKey:@"x"];
[vDict setObject:[NSNumber numberWithFloat:xVectors[i].y] forKey:@"y"];
[vDict setObject:[NSNumber numberWithBool:xVectors[i].on] forKey:@"on"];
[vArray addObject:vDict ];
}
return vArray ;
}
But I find it not so elegant.
I presume there should be a way to transform xVectors to an NSData in one
shot only, then add this NSData to my dictionary I will save to a file.
Do you know how to convert xVectors[16] to a NSData?
Best Regards
--
Lorenzo
email: email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden