Loading from archive?
- by fuzzygoat
Can anyone point me in the right direction, I have two sets of load/save methods below that I am playing with to save an array of objects out to disk and then load them back in. I am getting a little confused after calling "saveMoons" how I should go about loading that data back in ... any pointers would be great.
-(void)saveMoons:(NSString *)savePath {
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[moons encodeWithCoder:archiver];
[archiver finishEncoding];
[data writeToFile:savePath atomically:YES];
[data release];
[archiver release];
}
-(void)loadMoons:(NSString *)loadPath {
NSMutableData *data = [[NSMutableData alloc] initWithContentsOfFile:loadPath];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
// [self setMoons:[unarchiver ??????]];
}
.
// ------------------------------------------------------------------- **
// SIMPLER
// ------------------------------------------------------------------- **
-(void)saveMoons_SIMPLE:(NSString *)savePath {
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:moons];
[data writeToFile:savePath atomically:YES];
}
-(void)loadMoons_SIMPLE:(NSString *)loadPath {
[self setMoons:[NSKeyedUnarchiver unarchiveObjectWithFile:loadPath]];
}
// ------------------------------------------------------------------- **
//
// ------------------------------------------------------------------- **
gary