简体   繁体   English

核心数据VS SQL语句,用于iPhone开发的gd是哪一个?

[英]Core Data VS SQL Statement, which one is gd for iphone development?

iPhone 3.0 support the Core Data, it seems a great tool for developer. iPhone 3.0支持Core Data,对于开发人员来说似乎是一个很好的工具。 But SQL statement seems it is easier to get start, but core data is easier for maintaining db. 但是SQL语句似乎更容易上手,但是核心数据更易于维护db。 But I'm considering the SQL statement, because it seems have better performance. 但是我正在考虑使用SQL语句,因为它似乎具有更好的性能。 I am consider which one is better for iPhone development, any suggestion? 我正在考虑哪种方法更适合iPhone开发,有什么建议吗?

The answer is actually much simpler than either of those blog posts make it appear. 答案实际上比任何一个博客文章都更简单。 The rule is: 规则是:

  1. If you are developing for any OS X platform; 如果您正在开发任何OS X平台;
  2. If you are not accessing a proprietary format; 如果您不访问专有格式; and
  3. If your persistence file does not need to be read on a non OS-X platform 如果不需要在非OS-X平台上读取您的持久性文件

Then you should go with Core Data. 然后,您应该选择核心数据。 It is that simple. 就这么简单。 Core Data gives you so many features and the ease of use compared to straight SQL makes the choice simple. 与直接SQL相比,Core Data提供了许多功能,并且易于使用,使选择变得简单。 As far as performance, that is a red herring. 就性能而言,这是一个红鲱鱼。 Where it counts, Core Data can and does easily out perform custom code accessing a SQLite database. 无论在哪方面,Core Data都可以而且很容易执行访问SQLite数据库的自定义代码。 However, performance on Cocoa Touch is actually a secondary concern. 但是,可可触摸的性能实际上是次要的问题。

The primary concern is memory. 主要关注的是内存。 You have a tiny amount of memory in which to work with on Cocoa Touch and your data model can easily blow that out. 您可在Cocoa Touch上使用的内存很少,您的数据模型很容易将其耗尽。 Core Data solves that issue. 核心数据解决了这个问题。 It watches how much memory it is using and will drop objects out of memory automatically when it receives a memory warning. 它监视正在使用的内存量 ,并在收到内存警告时自动将对象从内存中删除。 All of that fairly complex code you would have to write yourself if you used SQLite directly. 如果直接使用SQLite,则必须编写所有相当复杂的代码。

Less time coding your data model means you have more time making your application great. 减少对数据模型进行编码的时间意味着您有更多的时间来使应用程序变得更好。

This provides a reasonable list of the pros and cons of either approach: http://maniacdev.com/2009/09/iphone-sqlite-vs-core-data- –-which-to-choose/ 这提供了两种方法的优缺点的合理列表: http ://maniacdev.com/2009/09/iphone-sqlite-vs-core-data- –-which-to-choose /

The recommendation is to use Core Data as it makes things so much easier in the long term. 建议使用Core Data,因为从长远来看,它使事情变得容易得多。

There is an in-depth explanation of the differences between the 2 here: http://cocoawithlove.com/2010/02/differences-between-core-data-and.html 这里有两个之间的区别的深入解释: http : //cocoawithlove.com/2010/02/differences-between-core-data-and.html

That's a great read. 这是一本好书。 The 2 approaches are different and both have their pros and cons. 两种方法各有千秋。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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