I have a NSTabViewController with a NSTextView in one tab. The text is saved in core data. I save the text when the view disappears.
override func viewWillDisappear()
{
super.viewWillDisappear()
self.saveText()
}
But how do I save the text when the document itself closes? At the moment I save on every keystroke, but that is probably too excessive. Is there a better way?
func textDidChange(notification: NSNotification)
{
self.saveText() //save text after every keystroke => excessive but works
}
edit:
func saveText()
{
guard let assumedObject = self.representedObject as? NSManagedObject else { return }
assumedObject.notes = self.textView.string
}