如何解决Swiftui:使用搜索栏过滤长列表非常慢
我有一个最多包含100个项目的列表。使用搜索栏过滤列表时,每个字母花费一些时间。 如何加快搜索速度? 一种可能的解决方案是仅在单击键盘上的搜索按钮之后进行过滤。
VStack {
SearchBar(text: $searchTerm,placeholder: "Suche")
}
List {
ForEach(gesetzestextTEMPO.filter {
self.searchTerm.isEmpty ? true : $0.titel1.localizedCaseInsensitiveContains(searchTerm)
|| $0.titel1.localizedCaseInsensitiveContains(searchTerm)
|| $0.artikel.localizedCaseInsensitiveContains(searchTerm)
|| $0.marginale.localizedCaseInsensitiveContains(searchTerm)
|| $0.absatz0.localizedCaseInsensitiveContains(searchTerm)
|| $0.absatz0litaz.localizedCaseInsensitiveContains(searchTerm)
})
{ item in
Part13(gesetzestextTEMPO: item,searchTerm: self.$searchTerm)
}
}```