Core data 如何为CoreData向多个关系写入NSPredicate

Core data 如何为CoreData向多个关系写入NSPredicate,core-data,nsfetchedresultscontroller,nspredicate,Core Data,Nsfetchedresultscontroller,Nspredicate,我在导航层次结构中有两个级别的uitableview。第一页是一个UITableView,它使用一个NSFetchedResultsController来显示设备的所有实例,效果非常好。在第二页中,我想返回特定设备的所有注释实体,以便在表格视图中显示它们 如何编写NSPredicate以仅返回相关注释 - (NSFetchedResultsController *)fetchedResultsController { if (_fetchedResultsController != n

我在导航层次结构中有两个级别的
uitableview
。第一页是一个
UITableView
,它使用一个
NSFetchedResultsController
来显示
设备的所有实例,效果非常好。在第二页中,我想返回特定
设备的所有
注释
实体
,以便在
表格视图中显示它们

如何编写
NSPredicate
以仅返回相关注释

- (NSFetchedResultsController *)fetchedResultsController {

    if (_fetchedResultsController != nil) {
        return _fetchedResultsController;
    }

    //Init Fetch Request
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

    //Entity the NSFetchedResultsController will be managing
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Note" 
                                              inManagedObjectContext:self.myContext];
    [fetchRequest setEntity:entity];

    //Sort Descriptors
    NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"noteTime" 
                                                                    ascending:YES];//Primary Sort
    NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"noteText" 
                                                                    ascending:YES];//Secondary Sort
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, 
                                                                sortDescriptor2, 
                                                                nil];

    //Set Sort Descriptors
    [fetchRequest setSortDescriptors:sortDescriptors];

    // limit Fetch to notes that belong to myEquipment
    //self
   // NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"item.name like '%@'", self.item.name]];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:PREDICATE GOES HERE];
    [fetchRequest setPredicate:predicate];



    [fetchRequest setFetchBatchSize:10];

    NSFetchedResultsController *frc = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest    
                                                                          managedObjectContext:self.myContext 
                                                                            sectionNameKeyPath:nil 
                                                                                     cacheName:@"Equipment"];
    //Set the Delegate Property
    frc.delegate = self;
    _fetchedResultsController = frc; 

    //Release Local Memory
    [sortDescriptor1 release];
    [sortDescriptor2 release];
    [sortDescriptors release];
    [fetchRequest release];

    return _fetchedResultsController;
} 

看一看,你会发现你必须做一些类似的事情

Equipment *equipment = // your equipment was passed from the previous tableview controller
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"equipment == %@", equipment];

这不会导致逻辑错误的获取请求吗?查询将是(设备==(实体:设备…)