This may be the wrong place to ask this but I am aware of NSExpression, but it seems it can only do primitive mathematics - am I wrong about this? I am able to do something like this: @Value-2/3+9-6
ect easily, but I would like to incorporate Max's, Min's, and possible a few other operations (instead of just multiplication, division, subtraction, and addition. Is that possible in the same equation, does it have to be converted multiple times? Any advice would be appreciated!
Asked
Active
Viewed 170 times
0

Torewin
- 887
- 8
- 22
2 Answers
0
You could try to use a "function" expression but that requires a rather unwieldy syntax in the expression string and is probably a stretch of the intended purpose of NSExpression unless you are actually implementing an aggregate type MIN/MAX function for predicates on a dataset.

Alain T.
- 40,517
- 4
- 31
- 51
-
I saw that NSExpression has Min, Max, Average, ect but I can't seem to find out how to use it. In Swift I would have: `Max(4+4, 0)` and I would also have other expressions in the same string. Perhaps I should work on parsing it myself? – Torewin Oct 10 '17 at 22:33
0
I figured it out.
For anyone who needs this - you can take any string and use:
functionName(x)
for most of the functions like sqrt
, multiplyby
, trunc
, ceiling
, ect
And then for the six with multiple variables (max
, min
, count
, average
, sum
, ect) you use functionName({x,y})
.
All can be used in a string with expressionValue(with: nil, context: nil)

Torewin
- 887
- 8
- 22