Cannot convert value of type '() -> ()' to expected argument type 'String' SwiftUI Button

Hello,

I'm trying to build a simple button. For some reason, I'm getting the following errors:

Cannot convert value of type '() -> ()' to expected argument type 'String'

Incorrect argument label in call (have 'action:_:', expected 'value:selected:')

Button(action: login) {
                ZStack {
                    RoundedRectangle(cornerRadius: 5)
                        .fill(Color.black)
                        .frame(width: UIScreen.main.bounds.width - 50, height: 50)
                    Text("Sign in")
                        .foregroundColor(.white)
                }
            }

All of my buttons in this particular project suddenly have this error. Any help would be greatly appreciated.

Thank you

This compile as long as the login value you use for your action is a method. Moreover, AFAIK Button doesn't have a init that takes value:selected:. Do you have a custom type call Button in your code ?

The Button initializer is like this:

 Button {
   login()
 } label: {
   ZStack {
                    RoundedRectangle(cornerRadius: 5)
                        .fill(Color.black)
                        .frame(width: UIScreen.main.bounds.width - 50, height: 50)
                    Text("Sign in")
                        .foregroundColor(.white)
                }
 }

as @thibautrichez said, this won’t work if ‘login’ is not an action

@sha921 @thibautrichez Thank you for your responses. I get the following errors with the code below:

Button {
                login()
            } label: {
                ZStack {
                    RoundedRectangle(cornerRadius: 5)
                        .fill(Color.black)
                        .frame(width: UIScreen.main.bounds.width - 50, height: 50)
                    Text("Sign in")
                        .foregroundColor(.white)
                }
            }

func login() {
print("test")
}

Incorrect argument label in call (have '_: label:', expected 'value:selected:')

Trailing closure passed to parameter of type 'String' that does not accept a closure

Thank you again for the help so far.

Cannot convert value of type '() -> ()' to expected argument type 'String' SwiftUI Button
 
 
Q