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?
1 Answer
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.
2 Comments
Fitzy
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.
Seth Spitzer
I'm unable to edit the post, but it's archivedDataWithRootObject not archiveDataWithRootObject