I am implementing a custom delete button, without using List and .onDelete, however I can't seem to get the IndexSet of the row and couldn't find example of this anywhere.
CartView.swift
struct CartView: View {
@ObservedObject var cartListVM = CartListViewModel()
func deleteCart(at offsets: IndexSet) {
offsets.forEach { index in
let cart = cartListVM.carts[index]
cartListVM.delete(cart)
}
cartListVM.getAllcarts()
}
var body: some View {
VStack {
ForEach(cartListVM.carts, id: \.id) { c in
VStack {
Text(c.menuName)
Button(action: {
deleteCart(at: indexSet)
// Can't seem to get the IndexSet here, how?
}) {
Text("Delete")
}
}
}
}
}
}
How do I get the indexset of the row? Thank you in advance.