简体   繁体   中英

Should a property list be managed by its own model object?

I am building an iPhone app that has some default data inside it via a property list. This data is the source for my Model. What is the best way to manage this data so the user can read (and in a couple of cases write) data from this plist?

I currently am subclassing NSObject and mapping the plist data to properties in that object, with methods to read/write data to the object. I have read about the NSCoding protocol and NSCoder but am not sure how to implement this in my custom class.

Any help will be appreciated.

Seems the answer is in this link:

http://mojomonkeycoding.com/tag/nscoding/

I guess you do not worry about super being initWithCoder in these cases.

If you really want to keep the data in a plist then you can use NSString:propertyList. It'll take the property list and parse it into the necessary structures for you. You can then use NSPropertyListSerialization to write it back out.

Frankly, what you're doing is easier unless you have a ton of different entities to track. There are a lot of ways to simply load and save data, if that's all you're interested in. Besides NSCoder (which is a lot of boilerplate code for my taste) you could use CoreData and not worry about the serialization process at all--CoreData manages it all for you semi-automagically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM