gpt4 book ai didi

iphone - NSPredicate 中自己的函数(NSString 的 round)

转载 作者:行者123 更新时间:2023-12-03 18:00:14 25 4
gpt4 key购买 nike

我遇到了 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)

此外,我相信 round: 方法应该返回一个 NSNumber *,而不是原始类型。

关于iphone - NSPredicate 中自己的函数(NSString 的 round),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7556882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com