Cover by Joe Conway, Aaron Hillegass

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

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

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required