What are some advantages of using Core Data? (as opposed to plist)

后端 未结 2 1483
隐瞒了意图╮
隐瞒了意图╮ 2021-01-01 14:11

I am relatively new to iOS and programming, and I made an app before, but it used a plist for storage, which I saved to the documents folder. Now, I am thinking about switch

相关标签:
2条回答
  • 2021-01-01 14:14

    It's a matter of what you're saving. For simple strings, arrays, dictionaries, it's fine to use a plist. For something more complicated (data, images, non-object information) or something with to-many relationships (think relationship between song to album, or photo to photographer), then something like a more robust solution might work better like SQLite.

    CoreData is an objective-c-based wrapper around SQLite. If you think you might want to something more complicated, CoreData might be the way to go.

    If you need a quick tutorial, I'd check out: http://www.raywenderlich.com/934/core-data-tutorial-getting-started

    This got me going and allowed me to learn the basics the workings of CoreData.

    Good luck!

    0 讨论(0)
  • 2021-01-01 14:33

    A few advantages off the top of my head:

    • Much better memory management. With a plist you must load the entire thing into memory; with Core Data only the objects you're currently using need to be loaded. Also, once objects are loaded, they're normally placeholder "fault" objects whose property data doesn't load until you need it.
    • Related to the above, when you have changes, you can save only the changed objects, not the entire data set.
    • You can read/write your model objects directly instead of converting them to/from something like an NSDictionary.
    • Built-in sorting of objects when you fetch them from the data store.
    • Rich system of predicates for searching your data set for objects of interest.
    • Relationships between entities are handled directly, as properties on the related objects. With a plist you would need to do something like store an object ID for a relationship, and then look up the related object.
    • Optional automatic validation of property values.

    Data models don't use arrays, but "to-many" relationships are modeled as sets.

    0 讨论(0)
提交回复
热议问题