Possibly a nooby question - how is encodeWithCoder
called? I need to use this to save objects in files on the iphone, I am just unsure of how it is actually called. Do I have to manually call it? If so, what do I use as input for the NScoder
argument?
Asked
Active
Viewed 1,758 times
3
1 Answers
5
You don’t call it yourself, you use NSKeyedArchiver instead:
NSData *serialized = [NSKeyedArchiver archivedDataWithRootObject:foo];
Where foo
is your object that conforms to NSCoding
. There’s also a method to save the archived object directly to a file.

zoul
- 102,279
- 44
- 260
- 354
-
But does that mean if I wanted to archive something like a simple NSArray it would have to conform to NSCoding? This seems a bit overcomplicated to me. – Fitzy Oct 14 '12 at 08:44
-
I'm unable to edit the post, but it's archivedDataWithRootObject not archiveDataWithRootObject – Seth Spitzer Mar 05 '14 at 21:57