Puede construir un predicado personalizado para negar el predicado que ya tiene. En efecto, usted está tomando un predicado existente y envolviéndolo en otro predicado que funciona como el operador NO:
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF contains '-'"];
NSPredicate *notPred = [NSCompoundPredicate notPredicateWithSubpredicate:pred];
[resultsArray filterUsingPredicate:pred];
Los soportes NSCompoundPredicate clase AND, OR y NOT tipos de predicado, por lo que podría pasar y construir un predicado compuesto grande con todos los caracteres que no quieres en tu matriz, luego filtra en él. Pruebe algo como:
// 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];
hago ninguna garantía en cuanto a su eficacia, sin embargo, y es probable que sea una buena idea poner los caracteres que puedan eliminar la mayoría de las cadenas de la matriz final de primera para que el filtro puede cortocircuito tantas comparaciones como sea posible.
Título modificado para reflejar mejor lo que esta preguntaw como preguntar. –