ios 在 iPhone 上使用 CoreData 或 SQLite?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1318467/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use CoreData or SQLite on iPhone?
提问by Hauke
Since CoreData has become available for the iPhone in OS 3.0, is it meant to be the answer to data persistence and replace all need for direct SQLite
?
由于 CoreData 在 OS 3.0 中已可用于 iPhone,它是否意味着要成为数据持久性的答案并取代对直接的所有需求SQLite
?
What reasons exist to still use SQLite
? What are advantages/disadvantages of SQLite
vs. CoreData
?
仍然使用的原因是什么SQLite
?SQLite
vs. 的优点/缺点是CoreData
什么?
回答by Brad Larson
This is a common question here:
这是这里的一个常见问题:
- "Core Data vs. SQLite for SQL experienced developers"
- "Core Data vs Sqlite and performance…"
- "Core Data vs sqlite3"
- "is it worth using core data for a simple sqlite app on the iphone with one table and no relationships or complicated subtable/views?"
- “针对 SQL 经验丰富的开发人员的核心数据与 SQLite”
- “核心数据 vs Sqlite 和性能……”
- “核心数据与 sqlite3”
- “是否值得在 iPhone 上使用一个简单的 sqlite 应用程序使用核心数据,该应用程序只有一个表,没有关系或复杂的子表/视图?”
In summary, Core Data can greatly simplify your code, particularly for complex object models. You get undo / redo support almost for free with it. It also provides some very significant performance benefits, particularly on the iPhone. Even though it seems counterintuitive, given how much overhead you'd think the framework has, in most cases you can beat the performance of hand-tuned SQLite using Core Data. On the iPhone, it does a great job of batching fetches to minimize memory usage.
总之,Core Data 可以极大地简化您的代码,尤其是对于复杂的对象模型。您几乎可以免费获得撤消/重做支持。它还提供了一些非常显着的性能优势,尤其是在 iPhone 上。尽管这看起来违反直觉,但考虑到您认为该框架有多少开销,在大多数情况下,您可以击败使用 Core Data 手动调整的 SQLite 的性能。在 iPhone 上,它在批量获取以最大限度地减少内存使用方面做得很好。
The one downside, as pointed out, is that this limits you by requiring iPhone OS 3.0 for your end users. However, this has not been a problem at all for my users, and will only become less of one going forward.
正如所指出的,一个缺点是这限制了您,因为您的最终用户需要 iPhone OS 3.0。然而,这对我的用户来说根本不是问题,而且只会越来越少。
回答by Mark Rushakoff
This might be a lesser benefit, but SQLite is a lot more portable between platforms, since Core Data is part of Cocoa, and SQLite is pure C. This means that if you wanted to port your application to PC, for instance, you would have less code to rewrite in the event that you use pure SQLite.
这可能是一个较小的好处,但 SQLite 在平台之间更具可移植性,因为 Core Data 是 Cocoa 的一部分,而 SQLite 是纯 C 语言。这意味着,例如,如果您想将您的应用程序移植到 PC,您将有如果您使用纯 SQLite,需要重写的代码更少。
Then if you wanted to develop anything else cross-platform using a local DB (not necessarily related to any iPhone apps), you would have already have some experience with SQLite.
然后,如果您想使用本地数据库(不一定与任何 iPhone 应用程序相关)开发任何其他跨平台的东西,那么您已经对 SQLite 有了一些经验。
回答by Pieter Jongsma
If you want your application to run on iPhones not running OS 3.0, you will have to use SQLite.
如果您希望应用程序在不运行 OS 3.0 的 iPhone 上运行,则必须使用 SQLite。
However, using CoreData (which uses SQLite as a backend, I believe) means you don't have to write your own database-interaction code which is quite a hassle to do, especially when you are doing relations etc.
但是,使用 CoreData(我相信它使用 SQLite 作为后端)意味着您不必编写自己的数据库交互代码,这很麻烦,尤其是在处理关系等时。
I use CoreData myself...
我自己使用 CoreData...