cocoa - Format string for NSPredicate with @avg collection operator -
is there way construct nspredicate following array can filtered average score larger than, say, 5?
nsarray *objs = @[ @{@"scores":@[@3, @5, @2]}, @{@"scores":@[@5, @2, @8, @9]}, @{@"scores":@[@7, @1, @4]} ]; i have tried various combinations, of 1 seemed promising (considering key path @avg.self works obtain average value of numbers in array through normal kvc):
nspredicate *pred = [nspredicate predicatewithformat:@"scores.@avg.self > 5"]; nsarray *filterd = [objs filteredarrayusingpredicate:pred]; the runtime error following:
nsunknownkeyexception', reason: '[<__nsarrayi 0x10011b7c0> valueforundefinedkey:]: class not key value coding-compliant key avg.
this predicate string works: scores.@count > 3, @ least collection operator can used in predicate.
if change scores.@avg.self > 5 scores.@avg.doublevalue > 5 work fine.
Comments
Post a Comment