-
Notifications
You must be signed in to change notification settings - Fork 113
Fix bug where document might not autosave when going to background #17
base: master
Are you sure you want to change the base?
Conversation
…thout dismissing the keyboard or pressing "Done"
|
||
} | ||
|
||
override func viewDidDisappear(_ animated: Bool) { | ||
super.viewDidDisappear(animated) | ||
|
||
NotificationCenter.default.removeObserver(self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed, observers are automatically removed nowadays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: it's not safe to assume that viewDidDisappear
means the end of the view controller's life.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, didn't know that!
document.text = self.textView.text | ||
|
||
if currentText != self.textView.text { | ||
document.save(to: document.fileURL, for: .forOverwriting, completionHandler: {success in print(success)}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is save(to, forOverwriting
the best approach here? Maybe document .updateChangeCount(.done)
is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I have a couple ideas on how to make this better. I'll try them out this weekend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Including the one you recommend
Ok, I fixed it up a bit. As a result of this, I also found what appears to be another bug. Textor doesn't load changes any other apps make if the document is open in Textor. I'll file an issue. |
This fixes the bug where the document would not save when going to the background unless the user tapped "Done" or dismissed the keyboard.