0
我正在学习Swift(只是一个爱好),并试图找出我应该如何保存和加载函数到基于文档的swift应用程序中的document.swift文件?我想知道如何保存和加载简单的txt文件。我正在使用NSTextView,所以我想我必须将其更改为NSString?如何将简单的保存加载函数添加到基于文档的Swift 3应用程序?
以下是这些功能的时刻:
override func data(ofType typeName: String) throws -> Data {
// Insert code here to write your document to data of the specified type. If outError != nil, ensure that you create and set an appropriate error when returning nil.
// You can also choose to override fileWrapperOfType:error:, writeToURL:ofType:error:, or writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
}
override func read(from data: Data, ofType typeName: String) throws {
// Insert code here to read your document from the given data of the specified type. If outError != nil, ensure that you create and set an appropriate error when returning false.
// You can also choose to override readFromFileWrapper:ofType:error: or readFromURL:ofType:error: instead.
// If you override either of these, you should also override -isEntireFileLoaded to return false if the contents are lazily loaded.
throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
}
谢谢!我进入它并报告是否有任何问题。 – paha