It looks like the standard deviation method for Core Data
on iOS does not exists, so I'm trying to do it by hand.
I'm just starting with NSExpression
so I'm struggling with this:
let numbers = [4, -2]
let numbersExpr = NSExpression(forConstantValue: numbers)
let avgExpr = NSExpression(forFunction: "average:", arguments: [numbersExpr])
let subExpr = NSExpression(forFunction: "from:subtract:", arguments: [numbersExpr, avgExpr])
let v = subExpr.expressionValue(with: nil, context: nil)
In my subExpr
I'm trying to subtract the average to all the values of my numbers array, but it crashes when trying to evaluate v on the last line.
How to do that with NSExpressions
?