Using filterArrayUsingPredicate always returns an empty array for selected Core Data objects

I am trying to use the NSArray filterArrayUsingPredicate: method to filter an array of master data-driven data. Here's the diagram:

NSArray *array = self.fetchedResultsController.fetchedObjects;

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

NSArray *filteredArray = [array filteredArrayUsingPredicate:predicate];

Does this always return an empty 'filterArray'? I assume this is my predicate, but I know that the objects in the "array" are managed objects with a key called "name". The value of "searchString" is fine, and I executed the executeFetch: before function.

+3
source share
1 answer

Your predicate is fine.

I would double check the 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];
+6

Source: https://habr.com/ru/post/1731869/


All Articles