在我的應用程序中,我有一個大約20,000個項目的大表。我在桌面上顯示它。但搜索欄在進行動態搜索時速度太慢。我已經讀過,NSPredicate方法是高性能的,然後是NSRange。 我不知道如何應用這種方法。nspredicate的快速研究
我的代碼是:
- (void)filterContentForSearchText:(NSString*)searchText
{
[self.filteredListContent removeAllObjects];
for (Book *book in listContent)
{
NSRange range = [book.name rangeOfString:searchText options:NSCaseInsensitiveSearch];
// is very very slow
if (range.location != NSNotFound)
{
[self.filteredListContent addObject:book];
}
}
}
如果我必須插入NSPredicate,到我們離開 「爲」?
對於aswer,我推這個代碼?進入「換」週期? – 2012-04-18 10:52:35
而不是循環。這取代了循環。 – ssteinberg 2012-04-18 10:53:58
好的,但我管理對象書? @「book.name包含%@」,是嗎? – 2012-04-18 10:56:41