O'Reilly logo

iOS Programming: The Big Nerd Ranch Guide by Joe Conway, Aaron Hillegass

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

NSKeyedArchiver and NSKeyedUnarchiver

You now have a place to save data on the filesystem and a model object that can be saved to the filesystem. The final two questions we must answer are: how do we kick off the saving and loading processes and when do we do it? To save BNRItems, you will use the class NSKeyedArchiver when the application exits.

In BNRItemStore.h, declare a new method.

-​ ​(​B​O​O​L​)​s​a​v​e​C​h​a​n​g​e​s​;​

Implement this method in BNRItemStore.m to send the message archiveRootObject:toFile: to the NSKeyedArchiver class.

-​ ​(​B​O​O​L​)​s​a​v​e​C​h​a​n​g​e​s​ {​ ​ ​ ​ ​/​/​ ​r​e​t​u​r​n​s​ ​s​u​c​c​e​s​s​ ​o​r​ ​f​a​i​l​u​r​e​ ​ ​ ​ ​N​S​S​t​r​i​n​g​ ​*​p​a​t​h​ ​=​ ​[​s​e​l​f​ ​i​t​e​m​A​r​c​h​i​v​e​P​a​t​h​]​;​ ​ ​ ...

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