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​]​;​ ​ ​ ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.