gpt4 book ai didi

ios - NSPredicate for NSString中的问题

转载 作者:行者123 更新时间:2023-12-01 19:01:57 25 4
gpt4 key购买 nike

在我的应用程序中,我正在使用CoreData.Amount值作为NSString存储在coreData中。在我的界面生成器中,我有两个文本字段。当我在文本字段中输入任何金额时,该金额将作为最小值和最大值接受。我想获取我输入的最小值和最大值之间的所有金额。

解决方案是什么。我只是通过这种方式Example不适用于我的项目,因为我想在NSPredicate方法上将字符串转换为整数。

我的代码是

 NSPredicate *p1= [NSPredicate predicateWithFormat:@"(amount.intValue => %@) && (amount.intValue <=%@)", text1.intValue,text2.intValue]];

请注意,金额以NSString形式存储在coredata中

最佳答案

NSPredicate * p1 = [NSPredicate predicateWithFormat:@“(amount.intValue =>%@)&&(amount.intValue <=%@)”,text1.intValue,text2.intValue]];

您不应该比较数字和字符串。比较其中一个。在这种情况下,您要比较数字。您应该将存储在模型中的源数据更改为数字。
=>应该是>=%d是整数参数格式,text1.intValue返回整数。使用%@会开玩笑,不会做您想要的事情。

记录谓词的内容,以便查看其包含的内容。但主要是更改模型中数据的类型。

关于ios - NSPredicate for NSString中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22218207/

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