Reputation: 31
I have a list with up to 100 items. While filtering the list with a searchbar it takes some time for every letter. How can I speed up the search? One possible solution is to filter only after click the search button on the keyboard.
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)
}
}```
Upvotes: 1
Views: 918
Reputation: 54446
Try the following:
List {
// ...
}
.id(UUID())
as proposed here: How to fix slow List updates in SwiftUI
Upvotes: 2