3

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 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
I'm unable to edit the post, but it's archivedDataWithRootObject not archiveDataWithRootObject

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.