1
我將如何使用(理想情況下)使用鍵值編碼集合運算符的單個謂詞來簡化此操作? (感興趣到底該數組是filteredGames
)CoreData獲取請求 - 複雜謂詞
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
。
感謝,馬丁。不知道子查詢,顯然除了NSExpression參考文獻中的條目外,幾乎沒有文檔 –