How to decode rootObject
I have a custom class and I am trying to save an array within my class. In the encodeWithCoder method I use the encodeRootObject:theShotArray to save the data. What should I use for the initWithCoder method. There doesn't seem to be a decodeRootObject method. Is there a better way to save an array开发者_运维知识库.
NSArray conforms to the NSCoding protocol, so you can say:
NSArray *rootArray = [[NSArray alloc] initWithCoder:myKeyedUnarchiver];
It may be a little confusing that NSArray's reference page doesn't specifically mention -initWithCoder:, but that's because that method is already described in the NSCoding protocol reference, and the NSArray reference page specifies NSCoding.
精彩评论