ios – Attempting to implement customized performance to a SwiftUI button, maintain getting a warning


I’m attempting to make a customized button the place I can implement my very own performance, like within the instance under:

MSButton {
    print("hi there")
}

Drawback is, I maintain getting the Expression of kind '(() -> Void)?' is unused warning, and the performance I add does not activate.

Right here is the code I made in an try and implement this:

struct MSButton: View {
    
    var motion: (() -> Void)?
    
    var physique: some View {
        Button() {
            motion // the place I get the warning.
        } label: {
            Textual content("Button")
        }
    }
}

What am I lacking that might enable me to get my motion to work correctly? Any assist can be tremendously appreciated.

Leave a Reply