Okay, so thanks to Martin, indicating that I should read the documents a little closer. This is the expected behavior, and here is what I did to get around it (use your opinion on whether this suits you):
I save my context once every 3 seconds, checking at the beginning if the context has any changes before I start the actual save: method on my NSManagedObjectContext . I added a simple increment / decrement NSUInteger ( _saveDisabler ) to the Core Data controller class, which changes in the following ways:
- (void)enableSaves { if (_saveDisabler > 0) { _saveDisabler -= 1; } } - (void)disableSaves { _saveDisabler += 1; }
Then, everything I do in my usual saveContext method does a simple check at the top:
if (([moc hasChanges] == NO) || (_saveDisabler > 0)) { return YES; }
This prevents saving from occurring and means that the focus is not stolen from any of my subclasses of the custom text field. For completeness, I also subclassed NSTextField and turned on / off saving in my Core Data controller in the following ways:
- (void)textDidBeginEditing:(NSNotification *)notification; - (void)textDidEndEditing:(NSNotification *)notification;
It may be a little dirty, but it works for me. I really want to hear about cleaner / less complicated methods if someone did it successfully differently.
source share