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: "")
}