These are simple fetches. In fact, you can use a NSFetchedResultsController, and set "color" as the section name, and it will return to you an array of all objects, and they will be grouped by color.
Something like...
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Car"];
NSSortDescriptor *sectionSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"color" ascending:YES];
NSSortDescriptor *nameSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObjects:sectionSortDescriptor, nameSortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSFetchedResultsController *fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"color" cacheName:@"CarCache"];
fetchedResultsController.delegate = self;
self.fetchedResultsController = fetchedResultsController;
NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
// Handle error...
}
Now, your data will be broken up into sections, one section per color, and the values in there sorted by name. To get the data, just look at the sections property of the FRC.