现在,我的程序中的 setupFetchedResultsController 返回所有“食物”类型的实体,但我只想要“食物”类型的实体,它们也由我当前显示的“列表”实体持有。
holdBy 定义了“Food”和“List”之间的关系
有没有办法做到这一点?
我的 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];
}