ios – NSPredicate问题超过平等

ios – NSPredicate问题超过平等,第1张

概述我有一个简单的NSPredicate,但没有给出正确的结果 NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF.data.squareFootage >= %@", filterSquareFootage];filteredArray = [[filteredArray filteredArrayUsing 我有一个简单的nspredicate,但没有给出正确的结果
nspredicate *resultPredicate = [nspredicate predicateWithFormat:@"SELF.data.squareFootage >= %@",filterSquareFootage];filteredArray = [[filteredArray filteredArrayUsingPredicate:resultPredicate] mutablecopy];

奇怪的是,这适用于所有6000> = 250,7000> = 250,8000> = 6000.但是,只要squareFootage == 10000,10000> =任何较小值的谓词都是false.
注意:10000 for squareFootage是使用UiSlider获取的最大值.如果我将值减小到任何较小的值,则谓词结果为true

我在这里遗漏了什么并使用谓词不正确吗?

解决方法 我假设您的属性存储为字符串而不是数字,因此
将值作为字符串进行比较:
"10000" < "250" < "6000"

使用NSNumber而不是Nsstring(或者某些标量类型作为NSInteger)应该解决问题.

如果无法更改squareFootage属性的数据类型,则以下内容
谓词应该有效:

[nspredicate predicateWithFormat:@"SELF.data.squareFootage.intValue >= %d",[filterSquareFootage intValue]]
总结

以上是内存溢出为你收集整理的ios – NSPredicate问题超过平等全部内容,希望文章能够帮你解决ios – NSPredicate问题超过平等所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1109218.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存