2012-12-04 64 views
1

我有一個我的對象的實例數組 - MyObject。每個實例具有一個字符串和一個數組屬性 - myArrayProperty包含另一個類的實例 - MyOtherObject我正在使用NSPredicate基於在myArrayProperty的值作爲這樣做一些過濾:NSPredicate檢查數組中的所有項目

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

在這種情況下otherObject屬性是MyOtherObject的字符串屬性。我懷疑是這個結構的問題:myArrayProperty.otherObjectPropert

我的問題是,我如何指示謂詞遍歷myArrayProperty中的所有項目?我想避免在這裏使用for循環。謝謝。

回答

1

可以使用...

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

我相信。

+0

輝煌!這樣可行!謝謝! –

+0

不用擔心,樂於幫忙。 – Fogmeister

0

您可以輕鬆地檢查形式NSObject的或形成一定的基類,輕鬆地做你的工作,如:

ViewController *cont ; 
NSMutableArray *array ; 

[array addobject : cont]; 


nslog (@"%@",array); 

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

} 

像明智的,而不是UIViewController中使用NSObject的或其他的基類..

相關問題