我将如何使用(理想情况下)带有键值编码集合运算符的单个谓词来简化这一点?(最后感兴趣的数组是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
。