I'm trying to us开发者_如何转开发e 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.
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];
精彩评论