Search code examples
iphoneiossqlitecore-datafmdb

CoreData or SQLite for iOS aggregation


I have an iPhone app that requires local storage.

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.

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?

The collections for aggregation over are not huge (max 100 objects say). I need to do things like distributions.

I know there is no concrete answer here, just would like some second options. Thanks


Solution

  • I use both Core Data and FMDB (an Objective-C wrapper around SQLite) in my app, and it works fine. 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.