我正在为我的核心数据模型编写一个 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];
}