Right now the setupFetchedResultsController in my program returns all the Entities of type “Food”, but I only want Entities of type “Food” that are also heldBy the “List” entity I am currently displaying.
heldBy defines the relationship between “Food” and “List”
Is there a way to do this?
My setupFetchedResultsController
- (void)setupFetchedResultsController
{
// 1 - Decide what Entity you want
NSString *entityName = @"Food"; // Put your entity name here
NSLog(@"Setting up a Fetched Results Controller for the Entity named %@", entityName);
// 2 - Request that Entity
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];
// 3 - Filter it if you want
//request.predicate = [NSPredicate predicateWithFormat:@"Role.name = Blah"];
// 4 - Sort it if you want
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)]];
// 5 - Fetch it
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
[self performFetch];
}
I think you can use predicate that you comment out.