Skip to main content
  1. About
  2. For Teams
Asked
Modified 7 days ago
Viewed 69 times
0

I am trying to create a swipe action where I can delete (Ideally trying to have a delete and edit button). I am having an issue with deleting under the swipe action.

I should note that I have class with an array of dates. I would like the user to have the option to delete a date that is in the array

            List {
                
                ForEach((0..<$A.Date.count).reversed(), id: \.self) {
                    i in (Text("\(String(format: "%02d",i+1)) -  \(A.Date[i], style: .date)"))
                        .swipeActions(edge: .trailing) {
                            **Button (role: .destructive) {
                               DeleteDate(dateToDelete: i) // Not Working
                                print("delete")
                                
                            }**  label: {
                                Label("Delete", systemImage: "trash")
                            }
                            .tint(.red)



private func DeleteDate(dateToDelete: Int) {
        A.Date.remove(at: dateToDelete)
            print("delete function was used")
            
        }

I tried a few functions and an .onDelete. The OnDelete works but currently will not allow me to add buttons if i try the swipe action.

2
  • Show a minimal reproducible code that produces your issue, see: minimal code. Show the class with the Dates, and how you declare A in your View. You should consider using the more robust ForEach(dates){ date in ...}, where dates is an array of Identifiable elements. See also the less desirable alternative enumerated Note, use the common naming practice for classes, properties and functions.
    workingdog support Ukraine
    –  workingdog support Ukraine
    2025-10-14 05:04:08 +00:00
    Commented Oct 14 at 5:04
  • This could be useful: stackoverflow.com/questions/57112426/…
    koen
    –  koen
    2025-10-14 05:31:32 +00:00
    Commented Oct 14 at 5:31

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.