SwiftUI: Tuple with State property wrapper

If possible, I am trying to create a tuple where one of the values can be modified and used for the expected argument Binding. Can this be done? Thank you.

Why not having the whole Tuple in State ?

Could you show code so that we understand better what you are trying to achieve ?

@Claude31

State var emailAlert: (active: Bool, dept: Department)

And I want to use it with the alert ViewModifier like so – .alert(emailAlert.dept.name, isPresented: *** I want to use the "active" value here ***) {}

I'm aware that this can be easily achieved using two independent variables, I'm just tryin to see if it's possible using a tuple.

This should work as expected (I changed Department to String for testing purpose):

struct ContentView: View { 
    @State var emailAlert: (active: Bool, dept: String) = (false, "None")
    var body: some View {
 
            Button(action: {
                print("Alert")
                emailAlert.active.toggle()
            },
                   label: {
                Text("Alert me")
                    .bold()
                    .frame(width: 280, height: 50)
                    .background(.blue)
                    .foregroundColor(.white)
                    .cornerRadius(10)
            })
            .alert(isPresented: $emailAlert.active) {
                Alert(title: Text("One"), message: nil, dismissButton: .cancel())
            }
    }
}

This worked. Thank you.

SwiftUI: Tuple with State property wrapper
 
 
Q