Sorry I wasn't clear earlier. If I open an existing document, change one property of one object and call saveDocument(), I get the error message about failure to remove a non-empty folder in the TemporaryItems, as shown in my first message and "Could not merge changes" message. As an experiment I tried running the same test but calling [myMOC save, &error) and all was well.
The docs for NSPersistentDocument say that "For an existing document, a save just invokes
save:
on the context.", but I see different results.
I believe safe save saves the file to the TemporaryItems folder and then moves it to the desired URL. After the failed saveDocument call, the folder still exists, empty, but I get the error shown in my initial post. It's also possible that this error is not related to the merge failure, but they always appear together. I wonder if there's some strange timing issue with core data writing out the version to the temp folder while the safe save is trying to delete it.
The code that fails is:
[self.managedObjectContext processPendingChanges];
@try
{
[self saveDocument:self];
}
@catch (NSException *exception)
{
NSLog(@"Oops");
} @finally {
}
But I get no exception.
The code that doesn't fail, but which doesn't try a safe save is:
[self.managedObjectContext processPendingChanges];
[self.managedObjectContext save:&saveErr];
if (nil != saveErr)
{
NSLog(@"Failed to save Error: %@", saveErr);
}
Any pointers would be appreciated.