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

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -