So, I've realised that I need to use NSCoding to save my custom objects to a plist.
The part I'm struggling with is exactly how I do that after I've implemented the initWithCoder
and encodeWithCoder
methods. They return id
and void
respectively, so if they've converted my objects into NSData or whatever they do to them, where's the data, so I can save it?
I have the methods set up thusly:
- (id)initWithCoder:(NSCoder *)decoder { // Decode
if (self = [super init]) {
self.name = [decoder decodeObjectForKey:@"gameName"];
self.genre = [decoder decodeObjectForKey:@"gameGenre"];
self.rating = [decoder decodeObjectForKey:@"gameRating"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder { // Encode
[encoder encodeObject:self.name forKey:@"gameName"];
[encoder encodeObject:self.genre forKey:@"gameGenre"];
[encoder encodeObject:self.rating forKey:@"gameRating"];
}
Trying to figure out what the next steps are to get these objects (which are already in an NSMutableArray) saved to a .plist, and recalled when re-opening the app.
Any help appreciated!