Swift - conversion of string to expression -
i working on application in simple mathematical expressions passed around strings (for example "2+3"). need execute these expressions make sure equal target.
in mathematica / wolfram language, 1 can convert strings expressions simple command toexpression[]. there equivalent in swift? if not, how might 1 convert string workable math?
use [nsexpression][1], this...
let expression = nsexpression(format:"2+3") if let result = expression.expressionvaluewithobject(nil, context: nil) as? nsnumber { print(result) } else { print("error evaluating expression") } here's blog post nshipster on using nsexpression (includes swift examples).
Comments
Post a Comment