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 Item, you will use the class NSKeyedArchiver when the application exits.

In ItemStore.swift, implement a new method that calls archiveRootObject(_:toFile:) on the NSKeyedArchiver class.

f​u​n​c​ ​s​a​v​e​C​h​a​n​g​e​s​(​)​ ​-​>​ ​B​o​o​l​ ​{​
 ​ ​ ​ ​p​r​i​n​t​(​"​S​a​v​i​n​g​ ​i​t​e​m​s​ ​t​o​:​ ​\​(​i​t​e​m​A​r​c​h​i​v​e​U​R​L​.​p​a​t​h​!​)​"​)​
 ​ ​ ​ ​r​e​t​u​r​n​ ​N​S​K​e​y​e​d​A​r​c​h​i​v​e​r​.​a​r​c​h​i​v​e​R​o​o​t​O​b​j​e​c​t​(​a​l​l​I​t​e​m​s​,​ ​t​o​F​i​l​e​:​ ...

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.