Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ElysianEagle

macrumors newbie
Original poster
Jun 29, 2009
7
0
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!
 
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.
 
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!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.