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.
精彩评论