Post

Replies

Boosts

Views

Activity

Reply to onDelete change label
Adding .swipeActions you can add Localized text or icon for swipe to delete case and the default .onDelete still hangs around to be used with EditButton() if you're using with iPhone and Mac app. Can add red trash icon which is universal instead of text. List { ForEach(myArray, id: \.id) { item in SomeView(item: item) .swipeActions(allowsFullSwipe: false) { Button(role: .destructive) { deleteItem(item: item) } label: { Label("Delete", systemImage: "trash.fill") // Can also add Localized Text here } } } .onDelete(perform: delete) .onMove { from, to in myArray.move(fromOffsets: from, toOffset: to) } } .toolbar { EditButton() } private func deleteItem(item: AltimetryItem) { if let index = myArray.firstIndex(where: { $0.id == item.id }) { withAnimation { myArray.remove(at: index) } } } func delete(at offsets: IndexSet) { myArray.remove(atOffsets: offsets) }
Jun ’23