Currently using Xcode 13 and IOS 15.
I am using CoreData to display a list of upcoming trips. On each trip I have 2 swipe actions, one to delete the trip, and the second one is to edit the trip. When the Edit button is selected I then trigger the showingEditTripScreen to true so that the EditTripScreen sheet is shown. I am passing the trip into this sheet to be edited. The problem is that no matter what Trip from the ForEach row is selected, it is always the first trip data that is being sent to the EditTripScreen. Am I doing this properly, or is their another solution. Thanks
ForEach(tripVM.trips, id: \.id) { trip in
TripCardView(trip: trip)
.listRowSeparator(.hidden)
//.padding(.horizontal)
.swipeActions(allowsFullSwipe: false) {
// Edit Trip
Button {
showingEditTripScreen = true
} label: {
Label("Edit", systemImage: "pencil.circle.fill")
}
.tint(.green)
// Delete Trip
Button {
tripVM.deleteTrip(trip: trip)
tripVM.getAllTrips()
} label: {
Label("Delete", systemImage: "trash.circle.fill")
}
.tint(.red)
}
.sheet(isPresented: $showingEditTripScreen, onDismiss: {
}, content: {
EditTripScreen(trip: trip)
})
}