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 are: how do you kick off the saving and loading processes and when do you do it? To save instances of BNRItem, 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​ {​ ​ ​ ​ ​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​]​;​ ​ ​ ​ ​/​/​ ​R​e​t​u​r​n​s​ ​Y​E​S​ ​o​n​ ​s​u​c​c​e​s​s​ ...

Get iOS Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.