在我的应用程序中,我正在使用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/