使用NSExpression计算小于的值? [英] Calculate lessthan value using NSExpression?
本文介绍了使用NSExpression计算小于的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于以下代码块:
NSString *formul=@"5 < 9";
NSExpression *e = [NSExpression expressionWithFormat:formul];
int result = [[e expressionValueWithObject:nil context:nil] intValue];
NSLog(@"formule:%d", result);
我收到错误:
由于未捕获的异常'NSInvalidArgumentException',原因:'无法解析格式字符串5< 9 == 1'
due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "5 < 9 == 1"'
推荐答案
您可以使用 NSPredicate
代替:
NSString *formul = @"15 < 9";
NSPredicate *predicate = [NSPredicate predicateWithFormat:formul];
BOOL b = [predicate evaluateWithObject:nil];
这篇关于使用NSExpression计算小于的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文