WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

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 {
                    Text(label)
                    Text("\(timer.timeRemaining)")
                }
                Spacer()
                Image(systemName: image)
                    .foregroundColor(stateButton ? Color.green : Color.red)
            }
            .padding(.horizontal, 10)
        }
        .frame(maxWidth: UIScreen.main.bounds.width, maxHeight: 40)
        .background(Color(UIColor.systemGray5))
        .foregroundColor(Color.black)
    }
}

   

You could try adding this

func myAction() {
    stateButton.toggle()
}

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: {
            action();
            print("qq")
        }) { Tetx("")}

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

   

Save 50% in my Black Friday sale.

SAVE 50% To celebrate WWDC22, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.