Aggregate Action with CoreData

196 views Asked by At

I have a CoreData "data base" and to simplify let's say that my objects have two attributes: a variable name and a variable value. I want to aggregate the content of the DB by "variable name" ("GROUP BY") and for each of the variables "names" , I want to find the standard deviation of the variables value. To do so, I use a NSExpression: expressionDescription.expression = NSExpression(format: "valeur_nombre.@stddev")

The issue is that I get the following error:

[error] CoreData: Exception was caught during NSPersistentStoreCoordinator -performBlock: Can't generate select target token for expression: valeur_nombre.@stddev with userInfo (null)

I have try to use the same code with different "aggregate action": -count -sum -max -min with no issues. However when I try to compute the average like writing in the Apple Docs: expressionDescription.expression = NSExpression(format: "valeur_nombre.@average")

I get this error :

[error] CoreData: Exception was caught during NSPersistentStoreCoordinator -performBlock: Can't generate select target token for expression: valeur_nombre.@average with userInfo (null)

If I replace "average" by "avg": expressionDescription.expression = NSExpression(format: "valeur_nombre.@avg") Then I got the right result Unfortunately, I didn't find any workaround for: -median -stddev

Can someone help me ?

0

There are 0 answers