A text field contains mathematical expressions like: 12+45-6
Is possible to convert this string to a number?
Can we use the predicate facility?
NSString *foo = @"((a*b)/c+(d/5))+15";
// dummy predicate that contains our expression
NSPredicate *pred = [NSPredicate predicateWithFormat:[foo stringByAppendingString:@" == 42"]];
NSExpression *exp = [pred leftExpression];
NSNumber *result = [exp expressionValueWithObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:4], @"a",[NSNumber numberWithInt:7], @"b",[NSNumber numberWithInt:2], @"c",[NSNumber numberWithInt:20], @"d",nil]context:nil];
NSLog(@"%@", result); // logs "33"<br/>
I also found this https://github.com/unixpickle/ANExpressionParser