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

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -