Can someone please explain to me why this doesn't work in SwiftUI 2.0 / iOS 14 / Xcode 12 and a valid workaround? AlertOne works fine but not AlertTwo. I'm trying to have alerts on both parent and child (nested) views. You can plug this right into Xcode to test if needed. Thank you.
import SwiftUI
struct ContentView: View {
@State private var alertOne = false
var body: some View {
VStack {
Button("Alert One") {
self.alertOne.toggle()
}
TestView().padding()
}
.alert(isPresented: $alertOne) {
Alert(title: Text("Alert One"), dismissButton: .default(Text("Got it!")))
}
}
}
struct TestView: View {
@State private var alertTwo = false
var body: some View {
Button("Alert Two") {
self.alertTwo.toggle()
}
.alert(isPresented: $alertTwo) {
Alert(title: Text("Alert Two"), dismissButton: .default(Text("Got it!")))
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}