Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does encodeWithCoder get called?

This will save an array (I think).

- (void)encodeWithCoder:(NSCoder *)encoder {
    [encoder encodeObject:myArray forKey:@"myArray"];
}

Do I have to directly call this method when I want to save an array or do I have to do something else?

like image 586
node ninja Avatar asked Sep 18 '10 13:09

node ninja


1 Answers

You don’t call this method directly. It’s called by a NSCoder subclass if it needs to serialize that object. If you want to encode an object graph use the class methods archivedDataWithRootObject: or archiveRootObject:toFile: of NSKeyedArchiver. This in turn will call the encodeWithCoder: method of your objects. Also note that every object in your array has to implement the NSCoding protocol.

like image 103
Sven Avatar answered Oct 17 '22 01:10

Sven