I was running into the same misunderstanding but it seems that success
just means that it didn't save the data, not that an error occured. In case of which there are no data to save, it won't return success but your data is still there.
This is the log output I'm getting after having success
to NO
and error
to nil
:
-08-01 14:07:01.003 TEST[39216:f03] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x8dbac50) → Saving <NSManagedObjectContext (0x8dbac50): *** UNNAMED ***> on *** BACKGROUND THREAD ***
2014-08-01 14:07:01.003 TEST[39216:f03] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x8dbac50) → Save Parents? 1
2014-08-01 14:07:01.004 TEST[39216:f03] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x8dbac50) → Save Synchronously? 0
2014-08-01 14:07:01.004 TEST[39216:f03] -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x8db99c0) NO CHANGES IN ** BACKGROUND SAVING (ROOT) ** CONTEXT - NOT SAVING
And in the NSManagedObjectContext+MagicalSave.m:41
file, you see that it checks for changes in the current context but doesn't save it if there's no new data:
if (![self hasChanges]) {
MRLog(@"NO CHANGES IN ** %@ ** CONTEXT - NOT SAVING", [self MR_workingName]);
if (completion)
{
dispatch_async(dispatch_get_main_queue(), ^{
completion(NO, nil);
});
}
return;
}