2017-07-04 71 views
1
NSPredicate *predicate3 = [NSPredicate predicateWithFormat:@"ANY %K.%K.%K CONTAINS[c] %@",@"Assets",@"TFloorAssets",@"AssetNo",strSearch]; 

NSArray *filteredPendingList = [NSMutableArray arrayWithArray:[arrOfAllAssetsCategory filteredArrayUsingPredicate:predicate3]]; 

我正在使用上述類型的代碼進行多級搜索?如何過濾多級數組來搜索字符串?

回答

-1

使用 「複合謂語」 像下面

NSPredicate *predicate = [NSCompoundPredicate orPredicateWithSubpredicates: 
          @[predicateEventsByAsset, predicateEventsByFloorAsset ,predicateEventsByAssetNo]]; 
self.filteredEventsArray = [self.eventsArray filteredArrayUsingPredicate:predicate]; 
+0

我可以知道downvote的原因嗎? –

+0

這個謂詞是「Assets contains [c]%@ OR TFloorAssets contains [c]%@ OR AssetNo [c] contains%@」)。問題是如何做「ANY Assets.TFloorAssets.AssetNo contains [c]%@」。 – Willeke

2

使用collection operator

[NSPredicate predicateWithFormat:@"ANY [email protected] contains[c] %@", strSearch] 

還是一個subquery

[[NSPredicate predicateWithFormat:@"SUBQUERY(Assets, $asset, ANY $asset.TFloorAssets.AssetNo contains[c] %@)[email protected] > 0", strSearch] 

或兩子查詢:

[NSPredicate predicateWithFormat:@"SUBQUERY(Assets, $asset, SUBQUERY($asset.TFloorAssets, $tFloorAsset, $tFloorAsset.AssetNo contains[c] %@)[email protected] > 0)[email protected] > 0", strSearch] 
+0

爲此我們使用@unionOfArrays或$?你能簡單地建議我還是提供一個鏈接,我可以閱讀這些東西? –

+1

我添加了答案的鏈接。 – Willeke

+0

thnks dude @Willeke –