April 2015
Intermediate to advanced
556 pages
17h 47m
English
Now you will add the ability to load files to your application. Once again, NSDocument has taken care of most of the details for you.
To do the unarchiving, you will use NSKeyedUnarchiver, which has the following handy method:
class func unarchiveObjectWithData(data: NSData) -> AnyObject?
In Document.swift, edit your readFromData(_:ofType:error:) method to look like this:
override func readFromData(data: NSData,
ofType typeName: String,
error outError: NSErrorPointer) -> Bool {
println("About to read data of type \(typeName).");
employees = NSKeyedUnarchiver.unarchiveObjectWithData(data) as! [Employee]
return true
return false
}
You could update the user interface after the XIB file is loaded, ...
Read now
Unlock full access