开发者

NSObject to file?

I have a class that is a sub-class of NSObject which contains 3 properties. How can I write this开发者_高级运维 object to a plist file?

Should I create a dictionary, populate it then write the dictionary to file?

or is there a simpler way?


You could use a dictionary, but generally, to write objects to a file, you should use NSKeyedArchiver. You will have to implement -encodeWithCoder: and -initWithCoder:. Then you can just use [NSKeyedArchiver archiveRootObject:myObject toFile:path];. For more information, see the Archives and Serialization Programming Guide.

However, for your simple 3-property case, a dictionary could be faster. It's really up to you, I suppose.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜