Distinct Value Array for View Controller Index Using Core Data
- by b.dot
Hi, I'm trying to create an index representing the first letter value of each record in a Core Data store to be used in a table view controller. I'm using a snippet of the code from Apple's documentation. I would simply like to produce an array or dictionary of distinct values as the result. My store already has the character defined within each record object. Questions:
1) I'm having a problem understanding NSDictionaryResultType. Where does the resulting dictionary object get received so that I can assign it's keys to the view controller? The code seems to only return an array.
2) If I include the line containing NSDictionaryResultType, I get no returns.
3) I realize that I could do this in a loop, but I'm hoping this will work.
Thanks!
NSEntityDescription *entity = [NSEntityDescription entityForName:@"People" inManagedObjectContext:managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
[request setResultType:NSDictionaryResultType]; // This line causes no no results.
[request setReturnsDistinctResults:YES];
[request setPropertiesToFetch :[NSArray arrayWithObject:@"alphabetIndex"]];
NSError *error;
NSArray *objects = [managedObjectContext executeFetchRequest:request error:&error];