views:

48

answers:

1

I'm building a carArray and want to filter the contents conditionally, using an NSPredicate, like so:

NSPredicate *pred;
switch (carType) {
  case FreeCar:
    pred = [NSPredicate predicateWithFormat:@"premium = NO"];
    break;
  case PremiumCar:
    pred = [NSPredicate predicateWithFormat:@"premium = YES"];
    break;
  default:
    pred = [NSPredicate predicateWithFormat:@"SOME PREDICATE THAT RETURNS EVERYTHING"];
    break;
}
self.carArray = [aCarArrayIGotFromSomewhere filteredArrayUsingPredicate:pred];

My question is, what is the correct syntax for the value I've stubbed in as SOME PREDICATE THAT RETURNS EVERYTHING which returns all of the instances in the array / set?

+5  A: 

To return all of the contents a given array / set, filter using the value TRUEPREDICATE. Also, if for any reason you wanted to none of the contents of an array / set, try the country cousin of TRUEPREDICATE, FALSEPREDICATE.

For more information about NSPredicate format string syntax, check the relevant docs.

Prairiedogg
Unfortunately the relevant docs are rather silent on how to use this TRUEPREDICATE thingie. I can't make it out in any case. So, I searched Stack Overflow and for once got no wiser :(
Elise van Looij