开发者

Using filteredArrayUsingPredicate always returns an empty array for Core Data fetched objects

开发者 https://www.devze.com 2022-12-19 18:26 出处:网络
I\'m trying to us开发者_如何转开发e NSArray\'s filteredArrayUsingPredicate: method to filter an array of core data managed-objects. Here\'s an outline:

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消