views:

246

answers:

1

I have made an class which conforms to the NSCoding protocol and does all the encode and decode stuff.

For my app, I simply want to persist an object from that class to the device and the next time when the app launches, I want to load that object back into memory.

Basically it's just an class which holds some user input information. For example the user starts writing a text but then quits the app. Next time I want to load that data object.

I guess I need NSKeyedArchiver? Is there a good tutorial on this? How do I do that?

+1  A: 

Yes you need NSKeyed(Un)Archiver. These 2 classes can convert your object to/from NSData which you can save/load it as a file.

To save your object to a file:

if (![NSKeyedArchiver archiveRootObject:your_object toFile:@"filename.plist"])
   // save failed.

To read the object from a file:

id your_object = [NSKeyedUnarchiver unarchiveObjectWithFile:@"filename.plist"];
if (your_object == nil)
  // read failed.
KennyTM
Where is that file stored? In the documents directory? Is this backed up by iTunes automatically?
dontWatchMyProfile
@mystify: Anywhere you like (of course you need to supply the full path.) It is backed up if the file is saved to ~/Documents.
KennyTM