error "Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure"


import SwiftUI
import UIKit

struct RegisterParams: View {
    @State private var toggle = false
    @State private var showAlert = false
    let userCredentials: UserCredentials

    var alert: Alert {
        Alert(title: Text("invalid email or password"), dismissButton: .default(Text("OK")))
    var body: some View {
                Form{ //Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure
                    Label("What's your email", systemImage: "at")
                    TextField("email", text:
                    Label("Enter a new password", systemImage: "lock")
                    SecureField("password", text: userCredentials.password)
                    Label("Tell us your nickname", systemImage: "person")
                    TextField("nickname", text: userCredentials.nickname)
                .frame(width: 400, height: 300)
                Button ("Sign Up") {
                    if (isValidEmailAddr(strToValidate: && isValidPassword(strToVailidate: userCredentials.password)) {
                        print("Email and Passowrd are valid")
                    else {
                .alert(isPresented: $showAlert, content: { self.alert })
                .frame(width:200, height: 100)
            }.frame(maxHeight: .infinity, alignment: .bottom)
struct RegisterParams_Previews: PreviewProvider {
    static var previews: some View {
        RegisterParams(userCredentials: UserCredentials.init(email: "", password: "", nickname: ""))

This is a registerview, the userCredentials constant calls a struct where I stored 3 strings(email, password, nickname)
I tried checking the formatting of the code, and if the brackets were correctly used, but I didn’t find any issue.
I think it has something to do with the userCredentials because it’s not a @State private var but I am not entirely sure about that.

>Solution :

Yes your hunch is correct, userCredentials needs to be wrapped with @State since you modify its properties

@State var userCredentials: UserCredentials

and then you need to pass a binding to each property where they can be changed

TextField("email", text: $
// same for the other properties.

I don’t know what UserCredentials is but the properties you are editing here needs to be var declared as well.

Leave a Reply Cancel reply