Swift3 使用NSDocument保存文件的最佳方法?

Swift3 使用NSDocument保存文件的最佳方法?,swift3,nsdocument,swift4,Swift3,Nsdocument,Swift4,我在保存文档时遇到问题,如调试区域中所示: 在中,我们可以找到一些保存文件的选项,但我不确定我需要哪些选项。有人愿意向我解释它们是什么,以及使用我选择的“WriteSafey”方法的最佳方法是什么 此外,该方法处理可能的错误,因此非原子写入操作似乎就足够了,但我想知道如何保留macOS的“版本控制”功能 NSFileVersion tried to tried to add a new generation and failed. Versioned file URL: file:///User

我在保存文档时遇到问题,如调试区域中所示:

在中,我们可以找到一些保存文件的选项,但我不确定我需要哪些选项。有人愿意向我解释它们是什么,以及使用我选择的“WriteSafey”方法的最佳方法是什么

此外,该方法处理可能的错误,因此非原子写入操作似乎就足够了,但我想知道如何保留macOS的“版本控制”功能

NSFileVersion tried to tried to add a new generation and failed. Versioned file URL: file:///Users/mike97/Downloads/test%20copy.xml, contents URL: file:///Users/mike97/Downloads/test%20copy~.xml, error: Error Domain=GSLibraryErrorDomain Code=2 "Unable to open /Users/mike97/Downloads/test copy~.xml" UserInfo={NSDescription=Unable to open /Users/mike97/Downloads/test copy~.xml, NSUnderlyingError=0x608000856020 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory" UserInfo={NSDescription=No such file or directory}}}
2017-06-19 20:19:53.069020+0200 XML Parser[2095:54823] NSDocument failed to preserve the old version of a document. Here's the error:
Error Domain=GSLibraryErrorDomain Code=2 "Unable to open /Users/mike97/Downloads/test copy~.xml" UserInfo={NSDescription=Unable to open /Users/mike97/Downloads/test copy~.xml, NSUnderlyingError=0x608000856020 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory" UserInfo={NSDescription=No such file or directory}}}
2017-06-19 20:19:53.118611+0200 XML Parser[2095:54823] <XML_Parser.Document: 0x6000001014d0>: An error occurred while attempting to preserve the backup file at file:///Users/mike97/Downloads/test%20copy~.xml: Error Domain=GSLibraryErrorDomain Code=2 "Unable to open /Users/mike97/Downloads/test copy~.xml" UserInfo={NSDescription=Unable to open /Users/mike97/Downloads/test copy~.xml, NSUnderlyingError=0x608000856020 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory" UserInfo={NSDescription=No such file or directory}}} ##
    override func writeSafely(to url: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType) throws {
            if let vc = self.windowController?.contentViewController as? ViewController {
                switch typeName {
                case "XML v1":
                    do {
                        try vc.parser?.save().write(to: url, options: [])
                    } catch  {
                        throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
                    }
                    break
..