Answer the question
In order to leave comments, you need to log in
Is it possible in swift to evaluate the value of a string/execute a string of code?
Is it possible in swift to evaluate the value of a string?
type:var value = evaluate("7*(10+2)")
Answer the question
In order to leave comments, you need to log in
OSX:
import Cocoa
var numericExpression = "7*(10+2)"
let expression = NSExpression(format: numericExpression)
var result = expression.expressionValueWithObject(nil, context: nil) as! NSNumber
print(result) // 84
import UIKit
var numericExpression = "7*(10+2)"
let expression = NSExpression(format: numericExpression)
var result = expression.expressionValueWithObject(nil, context: nil) as! NSNumber
print(result) // 84
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question