0

ill trying to code some calculator option. Please help me to create function pow(a, b) in NSExpression. need some like this:

extension NSNumber {
    func pow() -> NSNumber {
        return pow(self.doubleValue, 2)
    }
}

var functionString = "FUNCTION(3, 'pow')"
var functionExpression = NSExpression(format: functionString)
var functionValue = functionExpression.expressionValueWithObject(nil, context: nil)//9

Please help me, How can i set the second value instead of "2" and change this when i created a functionString?

Skie
  • 91
  • 1
  • 2
  • 13
  • You can use `**` or `raise:toPower:`, compare http://stackoverflow.com/questions/13045089/calculate-square-of-value-using-nsexpression. – Martin R Jan 28 '16 at 22:55
  • What are you trying to do can you explain it more excplicit? @Skie – Tom el Safadi Jan 28 '16 at 23:36
  • @Skie the problem here is the name you choose for your method it is probably conflicting with pow() method. change it to `func getPow()-> Double {` – Leo Dabus Jan 28 '16 at 23:43

0 Answers0