How to “quick save” in Core Data

The easiest way to access a readily available save method is by importing AppDelegate into the class that wants to execute the save. Then we call a method in AppDelegate:

AppDelegate *myAppDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
[myAppDelegate saveContext];

No reference to fetchedResultsController or managedObjectContext or any complex &error statements.

One thought on “How to “quick save” in Core Data

  1. If you have direct access to the managed object context you can also call something like this:

    [self.managedObjectContext save:nil];

    Or, if you’re interested in a potential error that may occur during saving:

    // create an error object
    NSError *error = nil;
    // call the above method, and if anything goes wrong, handle the error
    if (! [self.managedObjectContext save:&error]) {
        // handle the error here
        NSLog(@"Houston, we have a problem: %@", error);

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.