Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "12+6+ == 1"'
I want to validate expression is valid or not. And I am trying this using following code :
let equationString = "12+6+"
do {
let expr = try NSExpression(format: equationString)
if let result = expr.expressionValue(with: nil, context: nil) as? NSNumber {
let x = result.doubleValue
print(x)
} else {
print("failed")
}
}
catch {
print("failed")
}
I have used try-catch statement, but still I am getting crash here. Is there any solution for this?
Any help would be appreciated.
And you can use it with try:
TryCatch.h:
TryCatch.m: