gpt4 book ai didi

iphone - 对象和 NSPredicate

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:22:34 26 4
gpt4 key购买 nike

在我的应用程序中,我有一个包含大约 12000 个条目的大表。我在 tableview 上显示它。但是在进行动态搜索时搜索栏太慢了。我读到 NSPredicate 方法比 NSRange 更持久。

这是我的旧代码:

[self.filteredListContent removeAllObjects];
listContent = [[NSArray alloc] initWithArray:[dbAccess getAllBooks]];

for (Book *book in listContent)
{

NSRange range = [book.textBook rangeOfString:searchText options:NSCaseInsensitiveSearch];

if (range.location != NSNotFound)
{
[self.filteredListContent addObject:book];
}
}

我的新代码:

 [self.filteredListContent removeAllObjects];
listContent = [[NSArray alloc] initWithArray:[dbAccess getAllBooks]];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF like[c] %@",searchText];

[self.filteredListContent addObject:[listContent filteredArrayUsingPredicate:predicate]];

当我尝试执行此代码时,我收到此错误:“无法对对象进行正则表达式匹配。”

最佳答案

我会做一些更像...

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%k like[c] %@",propertyIAmLookingFor,searchText];

关于iphone - 对象和 NSPredicate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10067014/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com