SwipeAction in For Each

Hi,

Im trying to use ForEach without list to get rid of the navigation chevron , but the sipe to delete modifier stop working, is there a some solution ?

Kind Regards

                    Button(role: .destructive) {
                        deletePatient(patient: patient)
                    } label: {
                        VStack {
                            Label("Delete", systemImage: "trash")
                            Image(systemName: "Trash")
                        }
                    }
                }

You only show the button, not the swipe code. That does not give any information to understand what happens.

Please provide complete code so that we can reproduce.

Hello @Claude31 , thanks for the replay, below is the full code ..

import SwiftUI
import SwiftData

struct PatientsList: View {
    @Environment(\.modelContext) var modelContext
    @Query(sort: [SortDescriptor(\Patient.firstName), SortDescriptor(\Patient.birthday)]) var patients: [Patient]
    
    var body: some View {
        List {
            ForEach(patients) { patient in
                HStack {
                    NavigationLink (value: patient) {
                        PatientRow(patient: patient)
                    }
                }
                .alignmentGuide(.listRowSeparatorLeading) { _ in -50 }
                .listRowSeparatorTint(sysSecondary02)
                .swipeActions(edge: .trailing) {
                    Button(role: .destructive) {
                        deletePatient(patient: patient)
                    } label: {
                        VStack {
                            Label("Delete", systemImage: "trash")
                            Image(systemName: "Trash")
                        }
                    }
                }
            }
        }
        .scrollIndicators(.hidden)
        .foregroundStyle(sysSecondary08)
        .listStyle(.plain)
    }
    
    func deletePatient(patient: Patient) {
        modelContext.delete(patient)
    }
    init(sort: SortDescriptor<Patient>, searchString: String) {
        _patients = Query(filter: #Predicate {
            if searchString.isEmpty {
                return true
            } else {
                return $0.firstName.localizedStandardContains(searchString)
            }
        }, sort: [sort])
    }
}


#Preview {
    PatientsList(sort: SortDescriptor(\Patient.firstName), searchString: "")
}

swipeActions(edge:allowsFullSwipe:content:) currently works only within the context of a List.

To get rid of the navigation chevron in the List, you can use a value bound navigationDestination using navigationDestination(item:destination:)

For example:

@State private var colorShown: Color?

NavigationStack {
    List {
        Button("Mint") { colorShown = .mint }
        Button("Pink") { colorShown = .pink }
        Button("Teal") { colorShown = .teal }
    }
    .navigationDestination(item: $colorShown) { color in
        ColorDetail(color: color)
    }
}
SwipeAction in For Each
 
 
Q