简体   繁体   English

用于iOS聚合的CoreData或SQLite

[英]CoreData or SQLite for iOS aggregation

I have an iPhone app that requires local storage. 我有一个需要本地存储的iPhone应用程序。

My initial thought was to use core data, which is fine for a most of the app, however a major chunk is using aggregations on the data. 我最初的想法是使用核心数据,这对大多数应用程序来说都很好,但是主要的一块是在数据上使用聚合。 In SQLite this is the standard use of MIN, MAX, AVG, GROUP_BY etc. 在SQLite中,这是MIN,MAX,AVG,GROUP_BY等的标准用法。

But core data doesn't implement these very well, as it is primarily for object graph management. 但是核心数据并没有很好地实现这些,因为它主要用于对象图管理。 Would it matter if I did the calculations in Obj-C once loaded from CoreData, or should I stick with SQLite and forgo the usefulness of the CoreData system other parts? 如果我在从CoreData加载后在Obj-C中进行计算是否重要,或者我应该坚持使用SQLite并放弃CoreData系统其他部分的有用性?

The collections for aggregation over are not huge (max 100 objects say). 聚合的集合并不大(最多100个对象)。 I need to do things like distributions. 我需要做分配这样的事情。

I know there is no concrete answer here, just would like some second options. 我知道这里没有具体的答案,只是想要一些第二选择。 Thanks 谢谢

I use both Core Data and FMDB (an Objective-C wrapper around SQLite) in my app, and it works fine. 我在我的应用程序中使用Core Data和FMDB(一个围绕SQLite的Objective-C包装器),它工作正常。 Core Data adds a "Z" in front of your table and field names, so for example, if you have a Core Data entity called Contacts, you can do a query such as SELECT COUNT(*) FROM ZCONTACTS and it will give you back the results of the SQL query. 核心数据在表和字段名称前添加“Z”,例如,如果您有一个名为Contacts的核心数据实体,您可以执行查询,例如SELECT COUNT(*) FROM ZCONTACTS ,它会返回给您SQL查询的结果。

就个人而言,只要“大多数应用程序”不使用MIN,MAX,AVG,我就会留在CoreData中......因为那时“大多数应用程序”仍然与SQLite相比仍然很多。

You could use both. 你可以使用两者。 First aggregate your data, select the id and use 首先汇总您的数据,选择ID并使用

NSManagedObjectContext context; // Get it some how
NSManagedObject *obj = [context objectWithID:objectID];

to get the corresponding managed object. 获取相应的托管对象。

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

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