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 {
                Image(systemName: image)
                    .foregroundColor(stateButton ? Color.green : Color.red)
            .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 Fernando Olivares

SPONSORED Fernando's book will guide you in fixing bugs in three real, open-source, downloadable apps from the App Store. Learn applied programming fundamentals by refactoring real code from published apps. Hacking with Swift readers get a $10 discount!

Read the book

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.