prabu prabu - 1 year ago 151
Objective-C Question

Calculate lessthan value using NSExpression?

For the following block of code:

NSString *formul=@"5 < 9";

NSExpression *e = [NSExpression expressionWithFormat:formul];

int result = [[e expressionValueWithObject:nil context:nil] intValue];

NSLog(@"formule:%d", result);

I got error:

due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "5 < 9 == 1"'

Answer Source

You can use NSPredicate instead:

NSString *formul = @"15 < 9";
NSPredicate *predicate = [NSPredicate predicateWithFormat:formul];
BOOL b = [predicate evaluateWithObject:nil];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download