views:

131

answers:

1

EDIT_002: Further rewrite: if I save using the method below how would the method to load it back in look? (moons is an NSMutableArray of NSNumbers)

// ------------------------------------------------------------------- **
// METHOD_002
// ------------------------------------------------------------------- **

-(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];

    [archiver release];
    [data release];
}

gary

A: 

Found it, my problem was that I was using ...

[moons encodeWithCoder:archiver];

where I should have been using ...

[archiver encodeObject:moons];

Hence the loader would look like:

-(void)loadMoons_V3:(NSString *)loadPath {
    NSData *data = [[NSData alloc] initWithContentsOfFile:loadPath];
    NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
    [self setMoons:[unarchiver decodeObject]];
    [unarchiver finishDecoding];

    [unarchiver release];
    [data release];
}

gary

fuzzygoat