は、あなたが既に持っている述語を否定するカスタム述語を構築することができます。あなたが通過して構築できるので、
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF contains '-'"];
NSPredicate *notPred = [NSCompoundPredicate notPredicateWithSubpredicate:pred];
[resultsArray filterUsingPredicate:pred];
NSCompoundPredicateクラスがサポートAND、OR、およびNOT述語タイプ:実際には、既存の述語を取っているとNOT演算子のように動作し、別の述語でそれを包みますあなたがあなたの配列では望まないすべての文字を持つ大規模な複合述語をフィルタリングします。私も、その効率について何らの保証をしない、それはフィルタができるようにするために、最初の最終列からほとんどの文字列を排除する可能性がある文字を入れて、おそらく良い考えです
// Set up the arrays of bad characters and strings to be filtered
NSArray *badChars = [NSArray arrayWithObjects:@"-", @"*", @"&", nil];
NSMutableArray *strings = [[[NSArray arrayWithObjects:@"test-string", @"teststring",
@"test*string", nil] mutableCopy] autorelease];
// Build an array of predicates to filter with, then combine into one AND predicate
NSMutableArray *predArray = [[[NSMutableArray alloc]
initWithCapacity:[badChars count]] autorelease];
for(NSString *badCharString in badChars) {
NSPredicate *charPred = [NSPredicate
predicateWithFormat:@"SELF contains '%@'", badCharString];
NSPredicate *notPred = [NSCompoundPredicate notPredicateWithSubpredicate:pred];
[predArray addObject:notPred];
}
NSPredicate *pred = [NSCompoundPredicate andPredicateWithSubpredicates:predArray];
// Do the filter
[strings filterUsingPredicate:pred];
:ような何かを試してみてください可能な限り多くの比較を短絡してください。
出典
2009-07-22 16:17:07
Tim
変更があったタイトルは、この質問が何を求めているかをよりよく反映するように変更されました。 –