I'm trying to filter with searchController. I am getting a crash (-[__NSArrayI length]: unrecognized selector sent to instance
) at line NSRange productNameRange = NSMakeRange(0, [[_list valueForKey:@"name"] length]);
in the following code:
-(void)updateFilteredContent:(NSString*)searchText {
// Update the filtered array based on the search text and scope.
[self.searchResults removeAllObjects];
// Filter the array using NSPredicate
NSLog(@"_categories are %@",_categories);
for (NSDictionary *object in _categories) {
NSUInteger searchOptions = NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch;
NSRange productNameRange = NSMakeRange(0, [[_list valueForKey:@"name"] length]);
NSRange foundRange = [[_list valueForKey:@"name"] rangeOfString:searchText options:searchOptions range:productNameRange];
if (foundRange.length > 0) {
[self.searchResults addObject:object];
}
}
}
I've tried adding an if statement on the length like if ([[object valueForKey:@"name"] length] >0){
but it still crashing.
an example of the log for _list is:
_list names are (
"Honda",
"Ford",
Toyota,