I know Obj-c is a compiled language and doesn't offers any eval funcionality like python or ruby, but i need some dynamics functinality and i cannot decide between two different approac.
The problem: You have a string that describe a complex math formula, like
@"var_a + 4 - (3 * var_b)"
I already have a way evaluate the current value from var_a
and var_b
so, the first step is ok.
The second step is evaluate the formula and we have at least two different options:
- Create a string and try to evaluate with javascript engine (very bad idea).
- Map in objects obj-c the basic idea of formula matematica. I'm talking about create at example an object
SUM_Object
that accept two different operand and return the sum of the two parameters (and so on...like division etc). - Use DDMathParser.
I think the point number 2 is the best solution....any advices?
thanks.