我正在使用以下 NSPredicate
搜索自定义项目数组:
NSPredicate *query = [NSPredicate predicateWithFormat:@"[%K contains[cd] %@", column, searchString];
该数组包含具有多个变量的自定义类的项目(列指定要搜索的变量)。这对于 NSStrings
变量非常有用,但是,有一些是 int
或 double
变量,并且当它尝试对这些进行排序。有没有办法对 int
或 double
列表进行排序?
最佳答案
This works great for the variables that are NSStrings, however, there are some that are ints or doubles, and this code crashes when it trys to sort these.
发布填充数组的代码。
发布崩溃信息。
发布您如何尝试针对数组评估谓词。
如果 (1) 的答案是您将整数/ double 直接粘贴到数组中,那么这是行不通的;它们必须是对象。如果 (2) 的答案是发送到 NSNumber/NSValue 类的无法识别的选择器,那么您需要将 # 转换为字符串,contains[cd]
才能工作。
关于objective-c - 搜索 int 或 double 的 NSArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7690140/