Hello There,
How can I change the label for onDelete in SwiftUI to e. g. "Löschen"?
Here is my code (just a little bit of ContentView):
Thank you for answers.
How can I change the label for onDelete in SwiftUI to e. g. "Löschen"?
Here is my code (just a little bit of ContentView):
Code Block struct TodoListView: View { @State var textValue = "" @State var descriptionValue = "" @State var showAddTaskView: Bool = false @Environment(\.managedObjectContext) private var viewContext @FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \Task.date, ascending: false)]) private var tasks: FetchedResults<Task> var body: some View { NavigationView { List() { ForEach(tasks) { task in NavigationLink(destination: List { Text(task.beschreibung ?? "Kein Inhalt") } ) { if (task.title == "Unbenannt") { Text(task.title ?? "Unbenannt").italic() } else { Text(task.title ?? "Unbenannt") } } }.onDelete(perform: deleteTasks) } .listStyle(GroupedListStyle()) .navigationTitle("Todo-Liste") .navigationBarItems( trailing: Button(action: { showAddTaskView.toggle() }, label: { Image(systemName: "plus") .padding(.leading, 40) .padding(.bottom, 20) //.background(Color.yellow) }) )} .sheet(isPresented: $showAddTaskView, content: { NavigationView { List { TextField("Aufgaben-Name", text: $textValue) TextEditor(text: $descriptionValue) .padding() }.navigationTitle("Aufgabe") .navigationBarItems(leading: Button(action: { showAddTaskView.toggle() textValue = "" descriptionValue = " " }, label: { Text("Abbrechen").fontWeight(.regular) }),trailing: Button(action: { addTask() showAddTaskView.toggle() }, label: { Text("Hinzufügen") })) } }) } private func saveContext() { do { try viewContext.save() } catch { let error = error as NSError fatalError("Unresolved Error \(error)") } } private func deleteTasks(offsets: IndexSet) { withAnimation { offsets.map { tasks[$0] }.forEach(viewContext.delete) saveContext() } } private func addTask() { withAnimation { let newTask = Task(context: viewContext) if (textValue != "") { newTask.title = textValue } else { newTask.title = "Unbenannt" } if (descriptionValue != "") { newTask.beschreibung = descriptionValue } else { newTask.beschreibung = "Kein Inhalt" } newTask.date = Date() textValue = "" descriptionValue = " " saveContext() } } }
Thank you for answers.