gpt4 book ai didi

swift - 快速搜索数组并将其放入 UITableViewCell 中

转载 作者:行者123 更新时间:2023-11-30 14:13:36 25 4
gpt4 key购买 nike

现在我有一个包含大约 100000 个元素的数组。我已经为它创建了一个搜索栏,但我认为由于它通过我的手机解析的元素数量,在使用搜索栏时会出现滞后。有办法解决这个问题吗?

最佳答案

您尝试过使用NSPredicate吗?

NSMutableArray *array = [NSMutableArray arrayWithObjects:@"Nick", @"Ben", @"Adam", @"Melissa", nil];

NSPredicate *bPredicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] 'a'"];
NSArray *beginWithA = [array filteredArrayUsingPredicate:bPredicate];
// beginWithA contains { @"Adam" }.

NSPredicate *sPredicate = [NSPredicate predicateWithFormat:@"SELF contains[c] 'e'"];
[array filterUsingPredicate:sPredicate];
// array now contains { @"Nick", @"Ben", @"Melissa" }

话虽这么说,有 100000 个元素,持久存储不是更有意义吗?

关于swift - 快速搜索数组并将其放入 UITableViewCell 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31485163/

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