开发者

NSObject to file?

开发者 https://www.devze.com 2023-03-26 21:44 出处:网络
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?

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

精彩评论

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