2011-12-20 14 views
74

Ho un NSArray che voglio filtrare determinati oggetti usando un NSPredicate, speravo di poter usare NOT in poiché ho visto che posso facilmente fare un IN.NSArray con NSPredicate usando NOT IN

Così ho la mia matrice:

self.categoriesList 

tanto sono i valori che voglio per rimuovere:

NSArray *parentIDs = [self.cateoriesList valueForKeyPath:@"@distinctUnionOfObjects.ParentCategoryID"]; 

Questo mi dà un elenco di ParentCategoryID di per le categorie non voglio per visualizzare, così ho dato posso usare un NSPredicate per rimuoverli:

self.cateoriesList = [self.cateoriesList filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"CategoryID NOT IN %@",parentIDs]]; 

Questo fallisce:

reason: 'Unable to parse the format string "CategoryID NOT IN %@"' 

se volevo usare solo in che funziona perfettamente, naturalmente.

risposta

182

Che dire di NOT (CategoryID IN %@)?

+3

ummm ... sì che funziona - DOH! – Slee

+0

! (CategoryID IN% @) - funziona anche)) –

1

Che ne dici di utilizzare NONE?

[NSPredicate predicateWithFormat:@"NONE CategoryID IN %@", parentIDs]; 
+2

Nota che NESSUNO è solo per la relazione molti. Vedi http://stackoverflow.com/questions/12127618/nspredicate-the-left-hand-side-for-an-all-or-any-operator-must-be-either-an-nsa – Lubbo

Problemi correlati