Loading from archive?

Posted by fuzzygoat on Stack Overflow See other posts from Stack Overflow or by fuzzygoat
Published on 2010-03-16T18:47:26Z Indexed on 2010/03/16 18:51 UTC
Read the original article Hit count: 325

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa