views:

644

answers:

1

I'm trying to use NSArray's filteredArrayUsingPredicate: method to filter an array of core data managed-objects. Here's an outline:

NSArray *array = self.fetchedResultsController.fetchedObjects;

NSPredicate *predicate = [NSPredicate
                          predicateWithFormat:@"name contains[c] %@", searchString];

NSArray *filteredArray = [array filteredArrayUsingPredicate:predicate];

This is always returning an empty 'filteredArray'? I'm guessing it's my predicate, but I know the objects in 'array' are managed objects with a key called "name". The value of 'searchString' is okay and I have run performFetch: before.

+1  A: 

Your predicate is fine.

I would double-check array and searchString:

NSArray *array = self.fetchedResultsController.fetchedObjects;

NSLog(@"array = %@",array);
NSLog(@"array count = %d",[array count]);
NSLog(@"searchString = %@",searchString);

NSPredicate *predicate = [NSPredicate
                          predicateWithFormat:@"name contains[c] %@", searchString];

NSArray *filteredArray = [array filteredArrayUsingPredicate:predicate];
gerry3
Thanks - again a bit of debug, in the code, or using the debugger, is your friend.
petert