NSPredicate可以找到该对象的对象和搜索属性

时间:2015-07-01 03:47:57

标签: ios core-data nspredicate

enter image description here

以下内容查找具有Master.nameLast的所有Master对象,同样传递给字符串。虽然我希望NSPredicate检查对象是否与Master.nameLast匹配,并且该对象是否具有Master.batting.ab> 0

- (NSFetchedResultsController *)fetchedResultsController {

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

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSManagedObjectContext *context = [self managedObjectContext];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Master" inManagedObjectContext:context];
    [fetchRequest setEntity:entity];

    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"debut" ascending:YES];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"nameLast = [c]%@", nameLast];
    [fetchRequest setPredicate:predicate];

    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
    fetchRequest.sortDescriptors = sortDescriptors;

    _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:nil];

    return _fetchedResultsController;
}

我想找到一些找到所有Master对象与传入的字符串匹配的东西,并且有Master.batting.ab> 0

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(nameLast = [c]%@) AND (ANY batting.ab > 0)", nameLast];

0 个答案:

没有答案