NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

How transfer (()->()) -> ()

Forums > SwiftUI

Good afternoon everyone. Tell me how to make a function and pass

struct ButtonCustom: View {

    @ObservedObject var timer: TimerCountdown = TimerCountdown()

    @Binding var stateButton: Bool

**    typealias Tupl = (String) -> Void**

    var label: String = "Test"
    var action: Tupl

    var image: String = "exclamationmark.icloud"

    var body: some View {

        Button(action: **action(String) {} **) {
            HStack {
                HStack {
                Image(systemName: image)
                    .foregroundColor(stateButton ? :
            .padding(.horizontal, 10)
        .frame(maxWidth: UIScreen.main.bounds.width, maxHeight: 40)


You could try adding this

func myAction() {

and replace the Button with

Button(action: myAction )

You don't need Tupl at all. Then take it from there.


Thanks. implemented like this.

        Button(action: {
        }) { Tetx("")}

  ButtonCustom(stateButton: $statusVM.stateShow,
               label: "Show UserNotification",
               action: { statusVM.showUserData() },
     image: "icloud") 


Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.