1
extension String {
    var expression: NSExpression {
        return NSExpression(format: self)
    }
}

infix operator ^^
func ^^ (radix: Int, power: Int) -> Double {
    return Double(pow(Double(radix), Double(power)))
}

How can I add my infix operator in the NSExpression? I want to add ^^ as the power calculation operator in the NSExpression.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Nick Shern
  • 23
  • 5

1 Answers1

0

There is no public API for extending the syntax understood by NSExpression.

Try using DDMathParser instead. It already uses ** as the exponentiation operator.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848