AlertScene
A scene that renders itself as a standalone alert dialog.
Declaration
nonisolated struct AlertScene<Actions, Message> where Actions : View, Message : ViewOverview
Alert scenes present themselves in the center of the current display, and don’t attach to any particular window. The system prevents interaction with the app until someone dismisses the alert scene.
@main
struct MyApp: App {
@State var showLoginAlert = true
@State var loggedIn = false
var body: some Scene {
Window("Welcome User Window", id:"WelcomeWindow") {
...
}
.defaultLaunchBehavior(loggedIn ? .presented : .suppressed)
AlertScene("Login Required", isPresented: $showLoginAlert) {
Button("OK") {
...
}
}
}
}All the actions you provide in the ContentBuilder dismiss the alert when someone invokes them. Like the alert modifier, specify the role of the buttons with cancel or destructive. If you don’t provide any actions, the system automatically includes a button with the title “OK” that dismisses the alert scene.
Topics
Initializers
See Also
Presenting an alert
alert(_:isPresented:actions:)alert(_:isPresented:presenting:actions:)alert(_:item:actions:)alert(error:actions:)alert(isPresented:error:actions:)alert(_:isPresented:actions:message:)alert(_:isPresented:presenting:actions:message:)alert(_:item:actions:message:)alert(error:actions:message:)alert(isPresented:error:actions:message:)