我将如何使用(理想情况下)带有键值编码集合运算符的单个谓词来简化这一点?(最后感兴趣的数组是filteredGames。)
NSManagedObjectContext *context;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"Game" inManagedObjectContext:context];
NSArray *games = [context executeFetchRequest:request error:nil];
NSMutableArray *filteredGames = [[NSMutableArray alloc] init];
for (Game *game in games) {
NSInteger maxRoundNumber = [game.rounds valueForKeyPath:@"@max.number"];
Round *maxRound = [[game.rounds filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"number = %d", maxRoundNumber]] anyObject];
if (maxRound.someBoolProperty)
[filteredGames addObject:game];
}
游戏有 的NSSet属性rounds,Rounds并且Round有 的NSInteger属性number,我正在寻找那些Games最高数Round有一些BOOL属性的人someBoolProperty。