使用Core Data有什么优点? (而不是plist) [英] What are some advantages of using Core Data? (as opposed to plist)

查看:211
本文介绍了使用Core Data有什么优点? (而不是plist)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS和编程相对较新的,我之前做过一个应用程序,但它使用plist存储,我保存到文档文件夹。现在,我正在考虑切换到Core Data,但它看起来有点复杂,我不知道它是否会工作,我想要的。我将有一堆数据,我需要图形,所以我不知道是否Core Data是最好的,因为它似乎我不能在.xcdatamodeld文件中创建数组类型。 Core Data的其他一些优势是什么?它更快吗?更容易使用(一旦你设置它)?

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 switching over to Core Data, but it looks a little complicated, and I'm not sure if it will work for what I want. I am going to have a bunch of data which I need to graph, so I'm not sure if Core Data is best for this, as it seems that I cannot create an array type in the .xcdatamodeld file. What are some other advantages of Core Data? Is it faster? Easier to use (once you set it up)?

更新:对于任何人想知道,我完成了应用程序,这是完全值得的学习如何使用核心数据,这是一个很少复杂,我最初想。与plists做它本来是地狱。他们去做的方式似乎有点神秘,但如果你刚开始使用它,你会得到它。

Update: For anyone wondering, I finished the app, and it was totally worth it to learn how to use Core Data, and it was a lot less complicated that I originally thought. Doing it with plists would have been hell. The way they go about doing it seemed a little cryptic at first but if you just start using it you will get it. The relationships are really what is awesome about it.

推荐答案

我的头顶有几个优势:


  • 更好的内存管理。使用plist,你必须将整个东西载入内存;与核心数据只有您当前使用的对象需要加载。此外,一旦加载对象,它们通常是占位符故障对象,其属性数据不会加载,直到您需要它。

  • 与上述相关,

  • 您可以直接读取/写入模型对象,而不是将它们转换为像NSDictionary这样的对象。

  • 在从数据存储中提取对象时,内置对象排序。

  • 丰富的谓词搜索系统,用于搜索您感兴趣对象的数据集。
  • 实体之间的关系直接作为相关对象的属性进行处理。使用plist,您需要为关系存储对象ID,然后查找相关对象。

  • 可选的自动验证属性值。

  • 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.

数据模型不使用数组,但是to-many关系被建模为集合。

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

这篇关于使用Core Data有什么优点? (而不是plist)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆