Post

Replies

Boosts

Views

Activity

SwiftUI List with Section and ForEach loads all rows at once
Hello, coming from SO (https://stackoverflow.com/questions/71806868/swiftui-list-with-section-and-swipe-actions-loads-all-rows-at-once) I can't find any related post here. The issue: If you are using a ForEach inside a Section all rows are loaded at once. It seems like a bug or I misunderstood how to use them together. NOTE: I also posted a temporary workaround to mock a section in this SO thread. Here is the code snippet from SO: struct Item: Identifiable { var id = UUID() var name: String } struct Row: View { var item: Item static var counter = 0 init(item: Item) { self.item = item Row.counter += 1 print(Row.counter) } var body: some View { Text(item.name) } } struct ContentView: View { @State var items = (1...1000).map { Item(name: "Item \($0)") } var body: some View { List { ForEach(items) { Row(item: $0) .swipeActions(edge: .leading) { Button("Action", action: {}) } } } } }
1
4
966
Sep ’22