Skip to content
Dave DeLong edited this page Jan 4, 2014 · 17 revisions

You have an NSString. You want an NSNumber. You could use NSExpression to evaluate the string for you. However, this has a major flaw: extending it to support functions that aren't built-in to the parser requires for some awkward syntax. So if you really need sin(), you have to jump through some intricate hoops to get it.

You could use GCMathParser. This, however, isn't extensible at all. So if you really need stddev() or nthroot() functions, you're out of luck (unless you want to figure out how to modify the grammar and re-generate the parser).

Thus, DDMathParser. It is written to be identical to NSExpression in all the ways that matter, but with the major addition that you can define new functions and new operators as you need.