View Full Version : Core Data - grouping results
ElysianEagle
Jul 5, 2009, 02:23 PM
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!
Saladinos
Jul 5, 2009, 08:19 PM
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.
ElysianEagle
Jul 5, 2009, 11:10 PM
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!
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.