How do I serialize a simple object in iPhone sdk?

后端 未结 3 1857
清歌不尽
清歌不尽 2021-01-30 14:19

I have a dictionary of objects; they are all POCO objects that should be serializable. What technique should I look at for writing these to disk. I\'m looking for the simplest

3条回答
  •  闹比i
    闹比i (楼主)
    2021-01-30 14:44

    You do this in the same way you'd do it on Mac OS X: your POCOs must conform to the NSCoding protocol. See here for a conceptual reference, and here for the NSCoding reference.

    If the data isn't that crazy extensive and you don't have ridiculously complicated relationships between your objects, writing everything out as a plist is probably your best option; it's very fast to execute and simple to implement in your code. Like you said, CoreData will probably be a lot of extra work to adapt your code to, and sqlite really is only good for storing data that's perfect to be stored in a relational database. Keep in mind that sqlite is also slower and uses more resources than working with binary plists.

提交回复
热议问题