自己的函数(NSString的round)在NSPredicate [英] Own function (round for NSString) in NSPredicate
问题描述
我有NSPredicate的问题。
我有谓词:
NSPredicate * pr = [NSPredicate predicateWithFormat:@FUNCTION('12 .12345','round',3)= 12.123];
并为NSString定义扩展:
- (double)round:(NSNumber *)precision;
手动拨号时:
NSLog(@%f,[s round:3])
其中s是NSString,它的工作完美,但用于NSPredicate上升:
NSInvalidArgumentException:rease - [NSCFString round]:无法识别的选择器发送到实例。
我使用页面上使用的解决方案: http://funwithobjc.tumblr .com / post / 2922267976 / using-custom-functions-with-nsexpression
主要问题是在NSPredicate中使用round函数,欢迎
冒号(:
)必须是选择器在 FUNCTION
中,因此应该是 FUNCTION('12 .12345','round:',3)
p>
此外,我相信 round:
方法应该返回 NSNumber *
,而不是原始类型。
I got problem with NSPredicate.
I got predicate:
NSPredicate* pr = [NSPredicate predicateWithFormat:@"FUNCTION('12.12345','round',3) = 12.123"];
and defined extension for NSString:
-(double) round:(NSNumber*) precision;
When I call manually:
NSLog(@"%f",[s round:3])
where s is NSString, it's working prefectly, but used in NSPredicate rise: NSInvalidArgumentException: rease -[NSCFString round]: unrecognized selector sent to instance.
I use solution used on page: http://funwithobjc.tumblr.com/post/2922267976/using-custom-functions-with-nsexpression
The main question is to make round function in NSPredicate, so any other solutions are welcome
The colon (:
) must be part of the selector in the FUNCTION
, so it should be FUNCTION('12.12345', 'round:', 3)
Also, I believe the round:
method should return an NSNumber *
, not a primitive type.
这篇关于自己的函数(NSString的round)在NSPredicate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!