iosswiftnsexpression

custom NSExpression functions like sin(x)


I know how to add custom functions to NSNumber for NSExpression to work with it. But for use it i need to declarate a string like "FUNCTION(1, 'sin')". Is is any way to declarate it just like "sin(1)"?


Solution

  • No, you cannot extend the syntax understood by NSExpression(format:).

    For advanced expression parsing and evaluating, use 3rd party solutions such as DDMathParser.