SwiftUI Alert in Previews is not shown

Code Block
import SwiftUI
struct Alerts: View {
var body: some View {
Text("Where is the Alert?")
.alert(isPresented: .constant(true)) {
Alert(title: Text("Hello"),
message: Text("World"))
}
}
}
struct Alerts_Previews: PreviewProvider {
static var previews: some View {
Alerts()
}
}


does not show the alert, only shows text.

Live preview fails to start with message:

The application "App" may have exited. Try again or make another change to your code.

We also use previews for test to render previews for snapshots and we are unable to render Alerts.


you need a "NavigationView" for the "Alert" to show, for example:

Code Block
struct Alerts: View {
var body: some View {
NavigationView { // <---
Text("Where is the Alert?")
.alert(isPresented: .constant(true)) {
Alert(title: Text("Hello"), message: Text("World"))
}
}
}

}
I've tried to add NavigationView but it doesn't help

This is the full code I used on macos 11.4, xcode 12.5, target ios 14.5 and macCatalyst.
Is this not working for you?

Code Block
import SwiftUI
@main
struct TestApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
var body: some View {
Alerts()
}
}
struct Alerts: View {
var body: some View {
NavigationView {
Text("Where is the Alert?")
.alert(isPresented: .constant(true)) {
Alert(title: Text("Hello"), message: Text("World"))
}
}
}
}
struct Alerts_Previews: PreviewProvider {
static var previews: some View {
Alerts()
}
}

I tried to create an empty project and paste your code. Live preview for alert works now but it doesn't work for my project. I will investigate what's different between projects. Anyway, thank you for help @workingdogintokyo 
SwiftUI Alert in Previews is not shown
 
 
Q