Fix saving files in third party storages
@@ -805,16 +805,9 @@ fileprivate func parseArgs(_ args: inout [String]) {
return
}
- let text = textView.text
+ document?.text = textView.text
- DispatchQueue.global().async {
- do {
- try text.write(to: self.document!.fileURL, atomically: true, encoding: .utf8)
- completion?(true)
- } catch {
- completion?(false)
- }
- }
+ document?.save(to: document!.fileURL, for: .forOverwriting, completionHandler: completion)
}
/// The View controller is closed and the document is saved.
@@ -828,6 +821,8 @@ fileprivate func parseArgs(_ args: inout [String]) {
return
}
+ self.save(completion: { (_) in
+ DispatchQueue.main.async {
self.document?.text = self.textView.text
self.document?.close(completionHandler: { (success) in
if !success {
@@ -837,6 +832,8 @@ fileprivate func parseArgs(_ args: inout [String]) {
}
})
}
+ })
+ }
}
/// Shows documentation
