Hello All,
This is my first post so please be gentle :-)
I have been using this code that I learned from the Beginning iPhone SDK Development Book (Great Book By the way) They had a section in there where they showed how to load a UiTable from data in a plist.
That worked fine, and I added some search capabilities that were also found in the book. While this works very well for plist files that are relatively small, once they get larger, the searching slows down considerably.
Now I have been thinking of converting this to a SQL Lite database, but I was wondering of there was a better way I can search using the existing plist data (That has been loaded into an NSMutableArray.)
By just looking at this, it looks like the main reason it is slow is because it is looping through everything twice. I was hoping someone could provide some guidance as who to make this faster.
Any suggestions would be greatly appreciated.
Here is the Code Snippet that does the search.
Code:
-(void)handleSearchForTerm:(NSString *)searchTerm
{
NSMutableArray *sectionsToRemove = [[NSMutableArray alloc] init];
[self resetSearch];
for (NSString *key in self.keys) {
NSMutableArray *array = [names valueForKey:key];
NSMutableArray *toRemove = [[NSMutableArray alloc] init];
for (NSDictionary *item in array){
if ([[item objectForKey:@"title"] rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location ==NSNotFound)
[toRemove addObject:item];
}
if ([array count] == [toRemove count])
[sectionsToRemove addObject:key];
[array removeObjectsInArray:toRemove];
[toRemove release];
}
[self.keys removeObjectsInArray:sectionsToRemove];
[sectionsToRemove release];
[table reloadData];
}