NSPredicate检查数组中的所有项目

时间:2012-12-04 11:20:11

标签: iphone objective-c ios nspredicate

我有一个对象实例的数组 - MyObject。每个实例都有一个字符串和一个数组属性 - myArrayProperty,其中包含另一个类的实例 - MyOtherObject我正在使用NSPredicate根据myArrayProperty中的值进行一些过滤如此:

  NSPredicate *myPredicate = [NSPredicate predicateWithFormat:@"myArrayProperty.otherObjectProperty MATCHES %@", mySearchString];

在这种情况下,otherObject属性是MyOtherObject的字符串属性。我怀疑这个结构存在问题:myArrayProperty.otherObjectPropert

我的问题是,如何指示谓词遍历myArrayProperty中的所有项目?我想避免在这里使用for循环。谢谢。

2 个答案:

答案 0 :(得分:1)

你可以使用......

NSPredicate *myPredicate = [NSPredicate predicateWithFormat:@"ANY myArrayProperty.otherObjectProperty MATCHES %@", mySearchString];

我相信。

答案 1 :(得分:0)

您可以轻松检查表单nsobject或形成一些基类,并轻松完成以下任务:

ViewController *cont ;
NSMutableArray *array ;

[array addobject : cont];


nslog (@"%@",array);

for (UIViewController *crt in array ){
nslog (@"%@",crt);

}
像智者而不是UIViewcontroller使用NSObject或其他基类..