Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
How we can use alert menu before delete list items in SwiftUI?

I have list items in SwiftUI, and when I delete list items I want to delete after alert menu, like

"do want to delete your list items, ""yes" or "no"

is it possible?

  struct MyView: View {

    @State private var selectedUsers: MyModel?
 
    var body: some View {
        
            ScrollView(.vertical, showsIndicators: false, content: {
                
                VStack(content: {
                    
                    ForEach(datas){ data in
  
                        MyRowView(data: data)
                         
                            .contextMenu {

                                Button(action: {
                                    self.delete(item: data)
                                }) {
                                    Text("delete") 
                                }
                               
                            }
                            .onTapGesture {
                                selectedUsers = data
                            
                            }
                        
                    } .onDelete { (indexSet) in
                       self.datas.remove(atOffsets: indexSet)
                    }})
           })}

    private func delete(item data: MyModel) {
               if let index = datas.firstIndex(where: { $0.id == data.id }) {
                   datas.remove(at: index)
               }
           }}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In the delete action you set a @State bool to true, this triggers e.g. a ConfirmationDialog – and only after confirming there, you really delete:

           } .onDelete { (indexSet) in
                confirmDelete = true      // a @State var Bool
            }})
            .confirmationDialog("Do you really want to delete?", isPresented: $confirmDelete) {
                Button("Delete", role: .destructive) {
                    selectedUsers.remove(atOffsets: indexSet)
                }
                Button("Cancel", role: .cancel) { }
            }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!