开发者

How to decode rootObject

开发者 https://www.devze.com 2023-02-28 00:38 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消