The most "fun" part of SwiftUI is all the random times it doesn't work and I having no idea how to debug or understand why.

For example, the alert API, when used with a Menu only works if you put the `.alert()` modifier on the Menu itself (rather than the button that presents it):

gist.github.com/b3ll/61bee477e

¯\_(ツ)_/¯

@b3ll I’ve run into something very similar to this, and I think the issue is that as the alert is being processed, the menu closes, and the button disappears, so the alert modifier is no longer in scope.

I ‘get’ that, but it still ends up being a bit unintuitive, and confusing at first glance - putting this sort of modifier on the control that triggers it is nice and clean, but not always possible.

@matt1corey @b3ll I wish this could work so I could reuse a Button in multiple places and have the logic in a single place: present an alert or confirmationDialog for a delete button for example. Or present a paywall.

Follow

@alpennec @matt1corey @b3ll omg 100% this! Sick of resorting to this silly little pattern if I want a button + alert in a menu or swipe.

Sign in to participate in the conversation
The Not So Big Company

The home of The Not So Big Company on Mastodon.