I have a list of views with the new swipeActions method from iOS 15 beta, when I try to add a confirmation dialog (alert) when the user swipes on a row, I am getting an error that says
"Closure containing control flow statement cannot be used with result builder 'TableRowBuilder'"
Here is the code that results in this error.
var body: some View {
List {
ForEach(itemStore.items, id: \.id) { item in
if #available(iOS 15.0, *) { // Error appears here
ItemView(item: item)
.swipeActions() {
Button {
withAnimation { showingAlert.toggle() }
} .alert("Important message", isPresented: $showingAlert) {
Button("First") { }
Button("Second") { }
Button("Third") { }
} label: {
Label("Delete", systemImage: "trash")
}
}
.tint(.red)
} else {
// Fallback on earlier versions
ItemView(item: item)
}
}
}
}