O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Loading and NSKeyedUnarchiver

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:

c​l​a​s​s​ ​f​u​n​c​ ​u​n​a​r​c​h​i​v​e​O​b​j​e​c​t​W​i​t​h​D​a​t​a​(​d​a​t​a​:​ ​N​S​D​a​t​a​)​ ​-​>​ ​A​n​y​O​b​j​e​c​t​?​

In Document.swift, edit your readFromData(_:ofType:error:) method to look like this:

o​v​e​r​r​i​d​e​ ​f​u​n​c​ ​r​e​a​d​F​r​o​m​D​a​t​a​(​d​a​t​a​:​ ​N​S​D​a​t​a​,​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​o​f​T​y​p​e​ ​t​y​p​e​N​a​m​e​:​ ​S​t​r​i​n​g​,​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​e​r​r​o​r​ ​o​u​t​E​r​r​o​r​:​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required