【发布时间】:2013-01-06 17:02:34
【问题描述】:
我将如何使用(理想情况下)带有键值编码集合运算符的单个谓词来简化此过程? (最后感兴趣的数组是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。
【问题讨论】:
标签: objective-c ios core-data nspredicate key-value-coding