I have the following code to save an entity to the managed object context.
NSError *savingError = nil;
if ([self.managedObjectContext save:&savingError]) {
NSLog(@"Successfully saved the context.");
} else {
NSLog(@"Failed to save the context. Error = %@", savingError);
}
According to my documentation I understand the following: After inserting a new entity into the context, we must save the context. This will flush all the unsaved data of the context to the persistent store. We can do this using the save:
instance method of our managed object context. If the BOOL
return value of this method is YES
, we can be sure that out context is saved.
What I am not clear on is the syntax after save:
, specifically the ampersand '&' just before the local savingError variable
. What does this tell the compiler?
Take a look at: Why is `&` (ampersand) put in front of some method parameters?
In short: you need to pass a pointer to the NSError pointer, so save:
can assign an occasional error to savingError
.