Note that there are some explanatory texts on larger screens.

plurals
  1. POFilter NSFetchedResultsController to remove objects with same name
    primarykey
    data
    text
    <p>I have these objects that are unique except for two columns once of which I am using as the display in the UITableView. The UITableView will often show duplicates due to this. I need to filter out these duplicates somehow. </p> <p>Setting distinctResult on the FetchResult won't work in this case since that limits the functionality of the NSFetchedResultsController and it requires that the REsultType be a NSDictionary instead of a subclass of managed object. </p> <p>Doesn't anyone have any idea how I can filter these duplicates out using a predicate?? Remember that every field on these objects is unique except for two of them. </p> <pre><code>-(NSFetchedResultsController *) fetchGroupedObjects:(NSString *)entityDescription sortField:(NSString *)sortField withPredicate:(NSPredicate *)predicate { BPRAppDelegate *delegate = (BPRAppDelegate *)[UIApplication sharedApplication].delegate; NSManagedObjectContext *context = delegate.managedObjectContext; //NSError *error; //Fetch the data.... NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:entityDescription inManagedObjectContext:context]; [fetchRequest setEntity:entity]; NSSortDescriptor *groupDescription = [[NSSortDescriptor alloc] initWithKey:GROUP_NAME ascending:YES]; //Sort by Category Name NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:sortField ascending:YES]; NSMutableArray *sorts = [[[NSMutableArray alloc] init] autorelease]; [sorts addObject:sortDescriptor]; [sorts addObject:groupDescription]; [fetchRequest setSortDescriptors:sorts]; //[fetchRequest setResultType:NSDictionaryResultType]; //[fetchRequest setPropertiesToGroupBy:[entity.propertiesByName valueForKey:CONTRACTOR_NAME]; if (predicate != nil) [fetchRequest setPredicate:predicate]; //NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&amp;error]; //NSFetchResultsController [fetchRequest setFetchBatchSize:20]; NSFetchedResultsController *fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:GROUP_NAME cacheName:nil]; //Don't use a cache [fetchRequest release]; [sortDescriptor release]; [groupDescription release]; return fetchedResultsController; //You can't autorelease this thing... the requestor must do that. </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload