February 2014
Intermediate to advanced
560 pages
18h 58m
English
You now have a place to save data on the filesystem and a model object that can be saved to the filesystem. The final two questions are: how do you kick off the saving and loading processes and when do you do it? To save instances of BNRItem, you will use the class NSKeyedArchiver when the application “exits.”
In BNRItemStore.h, declare a new method.
- (BOOL)saveChanges;
Implement this method in BNRItemStore.m to send the message archiveRootObject:toFile: to the NSKeyedArchiver class.
- (BOOL)saveChanges
{
NSString *path = [self itemArchivePath];
// Returns YES on success
return [NSKeyedArchiver archiveRootObject:self.privateItems
toFile:path];
}
The archiveRootObject:toFile: method takes ...
Read now
Unlock full access