November 2013
Beginner
325 pages
9h 47m
English
To add the ability to save and reopen a task list, you need to override two methods inherited from BNRDocument’s superclass, NSDocument:
- (NSData *)dataOfType:(NSString *)typeName
error:(NSError **)outError
{
// This method is called when our document is being saved
// You are expected to hand the caller an NSData object wrapping our data
// so that it can be written to disk
// If there is no array, write out an empty array
if (!self.tasks) {
self.tasks = [NSMutableArray array];
}
// Pack the tasks array into an NSData object
NSData *data = [NSPropertyListSerialization
dataWithPropertyList:self.tasks
format:NSPropertyListXMLFormat_v1_0
options:0
error:outError];
// Return the newly-packed NSData object
Read now
Unlock full access