Monday, August 10, 2020 [Tweets] [Favorites]

SwiftUI Alerts

Thomas Hanning:

SwiftUI refreshes the view whenever the bool value changes since it is a state. As a consequence, the alert gets displayed if it’s set to true.


It’s not possible to add more than two buttons though.


But for a view it’s not so uncommon to have more than one scenario for displaying an alert. […] Unfortunately, this doesn’t work. The reason is that every view can only have one alert.

This is not a good advertisement for the Swift UI way of doing things.



Sometimes, in very specific use cases, declarative code is great. CSS and SQL come to mind.

I'm unconvinced using Swift for UI is one of those cases.

Old Unix Geek

How on earth is that an improvement? Old-school code:

switch ([UI alertWithTitle:"Hello,World" message:"blah" button0:"OK" button1:"Not OK"])
{ case 0: doOK(); break;
case 1: doNotOK(); break; }

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment