Post marked as solved
Click to stop watching this thread.
You have stopped watching this post. Click to start watching again.
contentPostList.repliessolved.tooltip
Replied In
SwiftUI List reload causes crash
Thank you! I spent so much time trying to figure it out what's the problem! I'm exactly in the same case trying to represent a dictionary that I mapped to a tuple[(Category: [Item])]it worked great but I really needed to sort it like that for instance:private var searchCategories: [(Category, [Item])] {
viewModel.searchResults
.map { $0 }
.sorted(by: \.key.rawValue) // You really need that to avoid crashes!
}And my viewsprivate var searchList: some View {
List {
ForEach(searchCategories, id: \.0, content: searchSection)
}.modifier(DismissingKeyboardOnSwipe())
}
private func searchSection(category: Category, items: [Item]) -> some View {
Section(header: header(category: category)) {
ForEach(items, content: searchItemRow)
}
}
private func searchItemRow(item: Item) -> some View {
NavigationLink(destination: ItemDetailView(item: item)) {
ItemRowView(item: item)
}
}