I use NSKeyedArchivers and NSKeyedUnarchivers for all of my saving needs at the moment, and I see one difference between what you're doing and what I'm doing. I know that you can just call encodeObject, but I've never had much luck with that. You might try something like this.
Code:
- (void) encodeWithCoder: (NSCoder *) encoder {
[encoder encodeObject: self.traditional forKey:@"traditional"];
[encoder encodeObject: self.simplified forKey:@"simplified"];
[encoder encodeObject: self.pinyin forKey:@"pinyin"];
[encoder encodeObject: self.english forKey:@"english"];
}
- (id) initWithCoder: (NSCoder *) decoder {
self.traditional = [[decoder decodeObjectForKey:@"traditional"] retain];
self.simplified = [[decoder decodeObjectForKey:@"simplified"] retain];
self.pinyin = [[decoder decodeObjectForKey:@"pinyin"] retain];
self.english = [[decoder decodeObjectForKey:@"english"] retain];
return self;
}
You may have to change your code to save the data as well. Something like this in your applicationWillTerminate function should work. wordArray is the array that holds your dictionary info when it's read into memory.
Code:
NSMutableData *theData = [NSMutableData data];
NSKeyedArchiver *encoder = [[NSKeyedArchiver alloc] initForWritingWithMutableData:theData];
[encoder encodeObject:wordArray forKey:@"wordArray"];
[encoder finishEncoding];
[theData writeToFile:yourFilePath atomically:YES];
[encoder release];
Then, you can read it back in your applicationDidFinishLaunching method like this.
Code:
NSData *theData = [NSData dataWithContentsOfFile:yourFilePath];
NSKeyedUnarchiver *decoder = [[NSKeyedUnarchiver alloc] initForReadingWithData:theData];
wordArray = [[decoder decodeObjectForKey:@"wordArray"] retain];
I did a tutorial over how to use NSKeyedArchivers and NSKeyedUnarchivers, which can be found in the tutorial section.