Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Fix bug where document might not autosave when going to background #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Vercantez
Copy link

This fixes the bug where the document would not save when going to the background unless the user tapped "Done" or dismissed the keyboard.

…thout dismissing the keyboard or pressing "Done"

}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)

NotificationCenter.default.removeObserver(self)
Copy link
Owner

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.

Copy link
Owner

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.

Copy link
Author

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)})
Copy link
Owner

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?

Copy link
Author

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.

Copy link
Author

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

@Vercantez
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants