Sean Oplinger
Sean Oplinger

Reputation: 49

Is there a way to have a button run multiple functions in SwiftUI?

I'm trying to have a button perform a sign out and change a boolean to false with one button. Is there any way to do this is or something similar in SwiftUI?

Button(action: GIDSignIn.sharedInstance()!.signOut, self.settings.settingsView.toggle()) {
           ZStack {
               Rectangle()
                    .frame(width: 300, height: 50)
                    .cornerRadius(5)
                    .foregroundColor(Color(.systemGray))
               Text("Sign Out")
                    .foregroundColor(.primary)
                     .font(Font.system(size: 25))
                        }
                   }

Upvotes: 2

Views: 3512

Answers (1)

creeperspeak
creeperspeak

Reputation: 5523

Instead of trying to pass multiple arguments into action you can just execute the closure and have it do as many things as you want. That would look more like this:

Button(action: {
    GIDSignIn.sharedInstance()!.signOut
    self.settings.settingsView.toggle()
}) {
    ZStack {
        Rectangle()
             .frame(width: 300, height: 50)
             .cornerRadius(5)
             .foregroundColor(Color(.systemGray))
        Text("Sign Out")
             .foregroundColor(.primary)
             .font(Font.system(size: 25))
     }
}

Upvotes: 4

Related Questions