0

我正在为我的核心数据模型编写一个 fetchedResultsController,并且只使用argumentArray 中的一项时遇到了谓词问题。如果数组有 3 个项目,它会打印出这个:NOT unique == "16C0629D-F8B6-4DF3-9AAD-820821B6D325"并且只搜索第一个项目。

我完整的 fetchedResultsController 代码如下。我搜索了一堆,似乎找不到关于我正在使用的方法的太多讨论。任何帮助表示赞赏。谢谢!

- (void)setupFetchedResultsController
{
  NSMutableArray *opponentUniques = [NSMutableArray array];
  for (Opponent *opponent in self.opponentArray) {
    [opponentUniques addObject:opponent.personUnique];
  }
  NSPredicate *searchPredicate = nil;
  if ([opponentUniques count] > 0) {
      searchPredicate = [NSPredicate predicateWithFormat:@"!(unique == %@)" argumentArray:opponentUniques];
  }

  NSFetchRequest *allPeople = [NSFetchRequest fetchRequestWithEntityName:@"Person"];
  allPeople.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]];
  allPeople.predicate = searchPredicate;
  self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:allPeople
                                                                    managedObjectContext:self.managedObjectContext
                                                                      sectionNameKeyPath:nil
                                                                               cacheName:nil];
}
4

2 回答 2

2

可能这会起作用: [NSPredicate predicateWithFormat:@"NOT (self.unique IN %@)", opponentUniques]

于 2013-04-13T15:47:08.517 回答
0

You are not using NSPredicate correctly. Take a look at NSCompundPredicate. You want something like andPredicateWithArray.

于 2013-04-13T15:44:53.660 回答