0
我想知道如何使用化合物NSPredicate?如何使用化合物NSPredicate
我已經做了如下的嘗試,但是currentInstall數組在開始時與在謂詞應用後完全相同。
NSArray *currentInstall = [coreDataController filterReadInstalls:selectedInstallID];
NSArray *tempArray = [currentInstalls filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"cHR == 0"]];
currentInstalls = [tempArray copy];
NSPredicate *predicateAreaString = [NSPredicate predicateWithFormat:@"area == %@", [myFilter objectForKey:@"area"]];
NSPredicate *predicateBString = [NSPredicate predicateWithFormat:@"stage == %@", [myFilter objectForKey:@"area2"]];
NSPredicate *predicateCString = [NSPredicate predicateWithFormat:@"partCode == %@", [myFilter objectForKey:@"area3"]];
NSPredicate *predicateDString = [NSPredicate predicateWithFormat:@"doorNo CONTAINS[cd] %@", [myFilter objectForKey:@"door"]];
NSPredicate *predicateEString = [NSPredicate predicateWithFormat:@"doorDesc CONTAINS[cd] %@", [myFilter objectForKey:@"doorDesc"]];
NSPredicate *compoundPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[predicateAreaString, predicateBString, predicateCString, predicateDString, predicateEString]];
NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[currentInstalls filteredArrayUsingPredicate:compoundPredicate]];
currentInstalls = [filteredArray mutableCopy];
任何幫助,將不勝感激。
好吧我會撥回到兩個然後從那裏工作,看看它是怎麼回事,這只是我第一次使用複合謂詞如此abit迷失atm ....但將繼續嘗試。 – HurkNburkS
好吧,所以我已經嘗試使用單個謂詞過濾數組,它工作。不太確定複合謂詞爲什麼不起作用。 – HurkNburkS
原來,它的工作原理...但返回一切,因爲我使用orPredicateWithSubpredicates,我已經更改爲andPredicateWithSubpredicates,它現在返回正確的信息。 – HurkNburkS