This code works:
NSString* equation = @"2.5*3";
NSExpression* expresion = [NSExpression expressionWithFormat:equation, nil];
NSNumber* result = [expresion expressionValueWithObject:nil context:nil];
NSLog(@"%@", result); // 7.5
But this one doesn't, it ends up in a NSInvalidArgumentException
NSString* equation = @"2.5<=3";
NSExpression* expresion = [NSExpression expressionWithFormat:equation, nil];
NSNumber* result = [expresion expressionValueWithObject:nil context:nil];
NSLog(@"%@", result); //I wanted result to be 1, as the expression is true
Does anyone know if there's a way to use NSExpression to evaluate logical expressions like that one?
Thanks.
Use NSPredicate instead of NSExpression: