|
I'm not able to trigger an Alert View from the onDelete closure, invoked deleting a list element, for example:
Any suggestion ? Thanks in advance. |
|
Hi @giurobrossi,
I think that a. views cannot be inserted via the
That would require you to introduce a |
|
That's fine, but the alert is shown after the execution of the onDelete callback: my purpose is to show the alert before the deletion of a list element. Unfortunately the indexSet of the deleting element is know only by the onDelete callback. |
|
I'm using CoreData. The template for Master / Detail with CoreData has this in the Event.swift
The content view has this:
So I would think you can make your own function for deleting (a class function in User), and only go there if the user agrees from the alert. And put the alert in .onDelete like you did. |
|
EDIT: actually this should be even easier with
this way you don't have to set the boolean and you also spare the force unwrap of the Optional (see here for reference: https://www.hackingwithswift.com/books/ios-swiftui/using-alert-and-sheet-with-optionals) (btw. it's nice to see how I can improve my own answer due to learning more stuff 🥳) original answer: Hi @giurobrossi, I've solved this issue (not having the indexSet after
in my struct and setting this in the
Hope that helps :) (and I'm feeling great right now because this is the first time ever I shared my SwiftUI knowledge 🥰) Greetings, Kevin |
|
Here is how I solved this. I wanted to write
Here's how I implemented it:
|
|
You may want to think about UX. As
or
So add another check might not be the best. If you just had a Button that delete then setting a 2nd check in case of accidental touches is a good idea but |
SPONSORED From January 26th to 31st you can join a FREE crash course for iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a senior developer!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.