3

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

Cameron
  • 4,181
  • 9
  • 36
  • 40

3 Answers3

1

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.

BP.
  • 10,033
  • 4
  • 34
  • 53
  • That sounds like an interesting idea, but isn't the point of CoreData abstracting away the dB? If apple change the underlying schema implementation you would have problems no? – Cameron Dec 09 '11 at 21:51
  • 1
    That is true, but I have used this technique on apps from iOS 3.0 to the current 5.0, and they all seem to work fine. In addition, I do not see Apple changing this scheme any time soon, but there should always be testing done when Apple makes major OS changes. – BP. Dec 11 '11 at 16:11
0

Personally I'd stay with CoreData as long as 'most of the app' doesn't use MIN, MAX, AVG... because then still 'most of the app' is still a lot then with SQLite.

V1ru8
  • 6,139
  • 4
  • 30
  • 46
0

You could use both. First aggregate your data, select the id and use

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

to get the corresponding managed object.

  • Not sure I follow. The aggregations are quite dynamic, I can't see how I could easily cache them to their own objects. – Cameron Dec 09 '11 at 21:52