次の述語を使用します。
NSString *format = @"SUBQUERY(testScoreObjects, $each, $each.score > $n && $each.scoreDate == testScoreObjects.@max.scoreDate)[SIZE] > 0";
NSDictionary *substitutions = @{@"n": @3}; // 3 is the value for n
NSPredicate *predicate = [[NSPredicate predicateWithFormat:format] predicateWithSubstitutionVariables:substitutions];
また
NSString *format = @"ANY SUBQUERY(testScoreObjects, $each, $each.score > $n).scoreDate == testScoreObjects.@max.scoreDate";
NSDictionary *substitutions = @{@"n": @3}; // 3 is the value for n
NSPredicate *predicate = [[NSPredicate predicateWithFormat:format] predicateWithSubstitutionVariables:substitutions];
どちらも配列をフィルタリングするために正しく機能しましたが、CoreDataがそれらをSQLに変換できるかどうかをテストしていません(したがって、フェッチ要求で使用できます)。
大規模な店舗を扱う場合、2番目の述語は(私が知る限り)学生ごとに1回だけ評価されるため、より効率的であるはずです。testScoreObjects.@max.scoreDate
もちろん、実際の結果は異なる場合があります。