我有一个简单的NSPredicate,它没有给出正确的结果
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF.data.squareFootage >= %@", filterSquareFootage];
filteredArray = [[filteredArray filteredArrayUsingPredicate:resultPredicate] mutableCopy];
奇怪的是,这适用于所有6000> = 250、7000> = 250、8000> = 6000。但是,只要squareFootage == 10000的谓词10000> =任何较小的值就为假。注意:squareFootage为10000是使用UISlider提取的最大值。如果我将值减小为任何较小的值,则谓词将得出true
我在这里遗漏了某些东西并错误地使用了谓词吗?
我假设您的属性存储为字符串而不是数字,因此将值作为字符串进行比较:
"10000" < "250" < "6000"
使用NSNumber
代替NSString
(或替代使用某些标量类型NSInteger
)应该可以解决此问题。
如果您不能更改squareFootage
属性的数据类型,那么以下谓词应该起作用:
[NSPredicate predicateWithFormat:@"SELF.data.squareFootage.intValue >= %d", [filterSquareFootage intValue]]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句