问题描述
如何在NSExpression中使用模运算符?如果我使用
how to use modulus operator with NSExpression? If i use
NSExpression *exp = [NSExpression expressionWithFormat:@"3%2"];
我遇到错误-***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'无法解析格式字符串 3%2 == 1。
I'm getting an error — *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "3%2 == 1"'.
有人可以解释如何正确地将模运算符与NSExpression一起使用吗?一个例子会很棒!
Can anyone explain how to correctly use modulus operator with NSExpression? An example would be great!
推荐答案
您可以使用 + [NSExpression expressionForFunction:arguments:]
,如@Sean McDonald建议的那样,或者如果您发现它太冗长,则可以使用格式字符串中预定义函数的语法:
You can use +[NSExpression expressionForFunction:arguments:]
, as @Sean McDonald suggests, or if you find that too verbose, you can use the syntax for a predefined function in a format string:
NSExpression *exp = [NSExpression expressionWithFormat:@"modulus:by:(3, 2)"];
这篇关于如何在NSExpression中使用模运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!