Gun13
Gun13

Reputation: 103

OSStatus error -4

I am creating document based app and I have strange problem - I can't open files which I saved. Each time I receive this error: "The document /name/ could not be opened". Here is output from NSError: The operation couldn’t be completed. (OSStatus error -4.) Error Domain=NSOSStatusErrorDomain Code=-4 "kCFMessagePortTransportError / kCSIdentityDeletedErr / unimpErr: / / unimplemented core routine" And my document class:

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
}
}

I really can't find any solution.

Upvotes: 3

Views: 775

Answers (0)

Related Questions