Re: NSArchiver? try again
Re: NSArchiver? try again
- Subject: Re: NSArchiver? try again
- From: Ondra Cada <email@hidden>
- Date: Thu, 30 Aug 2001 11:15:00 +0200
Mark's,
>
>>>>> Mark's Studio (MsS) wrote at Thu, 30 Aug 2001 10:19:19 +0200:
MsS> I have made 2 Classes Object1 and Object2 with all the NSCoder stuff
MsS> and in MyDocument i have one NSMutableArray Object1DB and that works
MsS> fine.
MsS>
MsS> But now i have another NSMutableArray Object2DB
MsS> but i can't figure out how to setup dataRepresentationOfType and
MsS> readFromFile if i have more than one object.
Containers are your friends.
MsS> - (NSData *)dataRepresentationOfType:(NSString *)aType
MsS> {
MsS> return [NSArchiver archivedDataWithRootObject:Object1DB];
return [NSArchiver archivedDataWithRootObject:[NSArray
arrayWithObjects:Object1DB,o2,nil]];
MsS> }
MsS>
MsS> - (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)docType
MsS> {
MsS> [self setObject1DB:[NSUnarchiver
MsS> unarchiveObjectWithFile:fileName]];
MsS> return YES;
MsS> }
NSArray *a=[NSUnarchiver unarchiveObjectWithFile:fileName];
[self set1:[a objectAtIndex:0]];
[self set2:[a objectAtIndex:1]];
Or use a dictionary, which is even more flexible. Or implement NSCoding in
your model and (un)archive directly the model.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc