I am trying to use iOS 15.0 swipeActions and confirmationDialog to delete an item in a List.
But what happens is that the wrong item gets deleted.
Here is my code:
struct ConversationsSection: View {
@State private var isShowingDeleteActions = false
let items = ["One", "Two", "Three", "Four", "Five"]
var body: some View {
List(items, id: \.self) { item in
Text(item)
.swipeActions(edge: .trailing) {
Button(role: .destructive) {
isShowingDeleteActions = true
print("Trying to delete: " + item)
} label: {
Label("Delete", systemImage: "trash")
}
}
.confirmationDialog("Delete item?", isPresented: $isShowingDeleteActions) {
Button("Confirm Delete", role: .destructive) {
print("Actually deleting: " + item)
isShowingDeleteActions = false
}
}
}
}
}
The output is:
Trying to delete: Two
Actually deleting: Four
Trying to delete: Five
Actually deleting: Three
So I swipe an item and confirmationDialog is presented. But inside confirmationDialog another item is passed. Why is that?

