Previously, I have an array in which I use NSKeyedArchiver to archieve.
[NSKeyedArchiver archiveRootObject:array toFile:docPath];
Called on applicationWillTerminate
and applicationDidEnterBackground
.
Upon starting up, in didFinishLaunchingWithOPtions
, the array is unarchieved:
NSMutableArray *array = [NSKeyedUnarchiver unarchiveObjectWithFile:docPath];
Everything was good. Since then, I added a Singleton class for Settings variables. I would like to archive the Singleton as well. How would I do that?
The part that confuses me is if I call the same message:
[NSKeyedArchiver archiveRootObject:singleton toFile:docPath];
How can the app know which object I want to unarchive when I call:
[NSKeyedUnarchiver unarchiveObjectWithFile:docPath];
Is it the array or the singleton?
The archiveRootObject accepts an (id) which to me means whatever I want. I can create a data class which includes the array and the singleton. Is that how I am suppose to do this? Is there a better way? Any suggestions are welcomed.
Thanks!