Core Data - grouping results

Discussion in 'iOS Programming' started by ElysianEagle, Jul 5, 2009.

  1. ElysianEagle macrumors newbie

    Joined:
    Jun 29, 2009
    #1
    i've been looking all over but can't find any examples of how to group results when you fetch data using Core Data. can anyone point me to any resources?

    by grouping i mean the same thing that you can do using the GROUP BY sql clause.

    thanks!
     
  2. Saladinos macrumors 68000

    Saladinos

    Joined:
    Feb 26, 2008
    #2
    You'd have to use a sort descriptor. To get it to group, override the compare: message to sort your array by a certain field.
     
  3. ElysianEagle thread starter macrumors newbie

    Joined:
    Jun 29, 2009
    #3
    hmm i did some more research and it looks like the way to go would be to use this method of NSFetchedResultsController:

    - (id)initWithFetchRequest:(NSFetchRequest *)fetchRequest managedObjectContext:(NSManagedObjectContext *)context sectionNameKeyPath:(NSString *)sectionNameKeyPath cacheName:(NSString *)name

    and then set the sectionNameKeyPath argument appropriately to group objects.

    havent tried it out yet but will try both approaches and let you know...thanks!
     

Share This Page