Alright guys, I'm struggling with this: I already managed to make custom functions without arguments work like this:
NSExpression(format: "function(1+1, 'myCustomFunction'").expressionValueWithObject(nil, context: nil) as! Double
But I have no idea of how to implement a custom function with arguments, I already tried passing the following String to NSExpression without success:
"function(1+1, 'myCustomFunctionWithArgument(42)')" // 42 as the argument
where the custom function looks like:
public extension NSNumber {
func myCustomFunctionWithArgument(x: Double) -> NSNumber
//...
}
However I get the following error:
-[__NSCFNumber myCustomFunctionWithArgument(42)]: unrecognized selector sent to instance 0xb000000000000045
2016-03-14 18:23:00.755 MyApp[3517:263390] *** Terminating app due to uncaught exception
I already searched everywhere, and I only find Objective-C answers, like on this tutorial: https://spin.atomicobject.com/2015/03/24/evaluate-string-expressions-ios-objective-c-swift/#comment-549856
In the end he explains how to do it on Objective-C, but not in Swift. Is there any way to do it? Btw this is for my Calculator app.