我正在创建基于文档的应用程序,我有一个奇怪的问题 - 我无法打开我保存的文件。每次收到此错误时:"文档/名称/无法打开"。这是NSError的输出:The operation couldn’t be completed. (OSStatus error -4.)
Error Domain=NSOSStatusErrorDomain Code=-4 "kCFMessagePortTransportError / kCSIdentityDeletedErr / unimpErr: / / unimplemented core routine"
我的文档类:
import Cocoa
class Document: NSDocument {
var saved: String = ""
let encoding = NSUTF8StringEncoding
override init() {
super.init()
// Add your subclass-specific initialization here.
}
override func windowControllerDidLoadNib(aController: NSWindowController) {
super.windowControllerDidLoadNib(aController)
// Add any code here that needs to be executed once the windowController has loaded the document's window.
}
override class func autosavesInPlace() -> Bool {
return true
}
override func makeWindowControllers() {
// Returns the Storyboard that contains your Document window.
let storyboard = NSStoryboard(name: "Main", bundle: nil)
let windowController = storyboard.instantiateControllerWithIdentifier("Document Window Controller") as! WindowController
self.addWindowController(windowController)
}
override func dataOfType(typeName: String) throws -> NSData {
saved = "tekst"
let dict: [String : AnyObject] = ["saved" : saved]
let data: NSData = NSKeyedArchiver.archivedDataWithRootObject(dict)
return data
}
override func readFromData(data: NSData, ofType typeName: String) throws {
let dict: NSDictionary = NSKeyedUnarchiver.unarchiveObjectWithData(data)! as! NSDictionary
print(dict.objectForKey("saved")!)
print("^^")
let e = NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
print("localized desc: ")
print(e.localizedDescription)
throw e
}
}
我真的无法找到任何解决方案。