Saving

The next puzzle piece is a method called whenever you would like to save changes from the _context to the _store. This is as easy as sending the context a save: message, as shown in Listing 1.9. This method will be placed in a new SAVING section.

Listing 1.9 CoreDataHelper.m: SAVING

#pragma mark - SAVING- (void)saveContext {if (debug==1) {    NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));}    if ([_context hasChanges]) {        NSError *error = nil;        if ([_context save:&error]) {            NSLog(@"_context SAVED changes to persistent store");        } else {            NSLog(@"Failed to save _context: %@", error);        }    } else {        NSLog(@"SKIPPED _context save, there ...

Get Learning Core Data for iOS: A Hands-On Guide to Building Core Data Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.