我正在尝试绑定swiftui按钮操作,并得到类似无法转换类型为'binding<()->的值; ()>“ 到预期参数类型“()->; void“
在看来
Button(action : $viewModel.action ) {
Text("Login")
}
在ViewModel中
class LoginViewModel: ObservableObject {
@Published var userid = ""
@Published var password = ""
@Published var selection : Int? = 0
//@Published var action : () -> void = {}
func action() {
}
}
您不需要在按钮操作中绑定,
Button(action : viewModel.action ) { // << no $ here !!
Text("Login")
}
其他的都应该没事。