I have an NSMutableArray *recordsArray, the keys are NSStrings, and the values are a custom object:
@interface DictRecord : NSObject{
}
@property (nonatomic, retain) NSString* word;
@property (nonatomic, retain) NSString *wordStatus;
Cocoa: How to save/archive an NSMutableArray containing custom objects
I want to save that NSMutable array, preferably in a non-binary (somewhat readable) format.
I have read through the docs and have added the encoding methods to DictRecord:
- (void) encodeWithCoder: (NSCoder *)coder
{
[coder encodeObject: _word forKey:@"word" ];
[coder encodeObject: _wordStatus forKey:@"wordStatus" ];
}
- (id) initWithCoder: (NSCoder *) coder
{
self = [super init];
if (self) {
self.word = [coder decodeObjectForKey:@"word"];
self.wordStatus = [coder decodeObjectForKey:@"wordStatus"];
}
Then I try to save using:
[recordsArray writeToFile:filePath atomically:YES];
A file is saved, but I can see that it's empty.
Can anyone tell me which steps I have omitted, or if I've gone about it the wrong way.
Thanks