Cannot Stack .presentation (Alerts)

I am unable to use more than one .presentation in a SwiftUI view. Below is a simple example.


import SwiftUI

struct ContentView : View {
    @State private var showingAlert = false
    @State private var showSavedAlert = false
    
    var body: some View {
        VStack {
            Text("Hello World")
            Button(action: {
                self.showingAlert = true
            }) {
                Text("Save")
            }
            Button(action: {
                self.showSavedAlert = true
            }) {
                Text("Save2")
            }
            
        }
        .presentation($showingAlert) {
            Alert(title: Text("Save File?"), message: Text("Do you want to save?"), primaryButton: .default(Text("Save")) {
                }, secondaryButton: .cancel())
        }
        .presentation($showSavedAlert) {
            Alert(title: Text("Another Save File?"), message: Text("Do you want to save?"), primaryButton: .default(Text("Save")) {
                }, secondaryButton: .cancel())
        }
    }
}

#if DEBUG
struct ContentView_Previews : PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
#endif

Does anybody have a workaround?

I have not tested and have little experience yet in SwiftUI.


But I understand the .presentation should apply to the buttons, not the stack.


So, I would write:


struct ContentView : View {
    @State private var showingAlert = false
    @State private var showSavedAlert = false
   
    var body: some View {
        VStack {
            Text("Hello World")
            Button(action: {
                self.showingAlert = true
            }) {
                Text("Save")
            }
        .presentation($showingAlert) {
            Alert(title: Text("Save File?"), message: Text("Do you want to save?"), primaryButton: .default(Text("Save")) {
                }, secondaryButton: .cancel())
        }

            Button(action: {
                self.showSavedAlert = true
            }) {
                Text("Save2")
            }
        .presentation($showSavedAlert) {
            Alert(title: Text("Another Save File?"), message: Text("Do you want to save?"), primaryButton: .default(Text("Save")) {
                }, secondaryButton: .cancel())

        }
        }
    }
}

Hope I did not mess the curly brackets, but that's the idea.

Cannot Stack .presentation (Alerts)
 
 
Q