Quote:
Originally Posted by mediatagging
I'm running Core Data and would like to have my data set return distinct values
Below is my code:
Code:
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Playlist" inManagedObjectContext:self.managedObjectContext];
NSDictionary *entityProperties = [entity propertiesByName];
[fetchRequest setEntity:entity];
[fetchRequest setReturnsDistinctResults:YES];
[fetchRequest setPropertiesToFetch:[NSArray arrayWithObject:[entityProperties objectForKey:@"name"]]];
It still returns duplicates. Any suggestions?
Thanks
|
We need to make two changes:
1. [fetchRequest setResultType:NSDictionaryResultType];
This will return an array of dictionaries instead of a FetchedResultsController
Store the fetch into an NSArray.