簡體   English   中英

NSArray上的多個NSPredicate

[英]Multiple NSPredicate on NSArray

我有一個NSPredicate數組和一組值。 現在,我想搜索如果所有的NSPredicatetrue為這個數組。 我正在使用這樣的循環:

bool valid = true;
for(NSPredicate* predicate in predicates){
                if([[searchValues filteredArrayUsingPredicate:predicate] count] == 0){
                    valid = false;
                    break;
                }
            }

有沒有更好的方法來做到這一點意味着以某種方式避免NSPredicate上的循環?

NSArray *predicates = ... // your array of predicates
NSPredicate *andPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:predicates];
BOOL valid = [[searchValues filteredArrayUsingPredicate:andPredicate] count] > 0;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM