Asim Roy
Asim Roy

Reputation: 10226

Calling SwiftUI button with action?

I have a struct like this. How do I call SwiftUIButton with action?

struct SwiftUIButton: View{
        let action: () -> ()
        var body: some View{
            Button(action: action){Text("Tap me")}
        }
    }

Upvotes: 1

Views: 154

Answers (1)

Asperi
Asperi

Reputation: 257543

Here it is

    SwiftUIButton {
        // do anything here
        print(">> button tapped")
    }

which is the same (but short variant) of

    SwiftUIButton(action: {
        // do anything here
        print(">> button tapped")
    })

Upvotes: 1

Related Questions