Reputation: 8111
So here's how I do the search:
add that array to the mutable array of results via addObjectsFromArray:
as such:
- (void)filterContentForSearchText:(NSString*)searchText
scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"SELF contains[cd] %@",
searchText];
NSArray *results = [self.allItems filteredArrayUsingPredicate:resultPredicate];
NSMutableArray *myResults = [[NSMutableArray alloc] init];
[myResults addObjectsFromArray:results];
self.searchResults = myResults;
[myResults release];
NSLog(@"%@", self.searchResults);
}
The problem I see is that I have to create a mutable array everytime a search is performed, which is whenever a "keyup" occurs. I was wondering if there was a better approach with this one.
Thanks in advance!
Upvotes: 0
Views: 319
Reputation: 5704
Step #4 is not makes sense. Assign filtered array directly but not thru myResults. In case of some internal logic you will need a copy of filtered results array you still can get it my calling copy method.
Upvotes: 1