views:

826

answers:

2

Hi,

I currently have the following piece of code

NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF contains '-'"];
[resultsArray filterUsingPredicate:pred];

This returns an array with the elements which contain '-'. I want to do the inverse of this so all elements not containing '-' are returned.

Is this possible?

I've tried using the NOT keyword in various locations but to no avail. (I didn't think it would work anyway, based on the apple documentation).

To further this, is it possible to provide the predicate with an array of chars that I don't want to be in the elements of the array. (The array is a load of strings).

Thanks,

Jon

+7  A: 

I'm not an Objective-C expert, but the documentation seems to suggest this is possible. Have you tried:

predicateWithFormat:"not SELF contains '-'"
John Feminella
Thanks, serves me right for not reading the document in its entirety. The only place I didn't try not was before self!
JonB
Glad I could help. :)
John Feminella
+1  A: 
Tim