Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 {
        VStack{
            Group{
                Form{ //Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure
                    Label("What's your email", systemImage: "at")
                        .bold()
                    TextField("email", text: userCredentials.email)
                    Label("Enter a new password", systemImage: "lock")
                        .bold()
                    SecureField("password", text: userCredentials.password)
                    Label("Tell us your nickname", systemImage: "person")
                        .bold()
                    TextField("nickname", text: userCredentials.nickname)
                        .bold()
                }
                .scrollContentBackground(.hidden)
                .textFieldStyle(RoundedBorderTextFieldStyle())
                .disableAutocorrection(true)
                .textInputAutocapitalization(.never)
                .frame(width: 400, height: 300)
    
                Button ("Sign Up") {
                    toggle.toggle()
                    
                    if (isValidEmailAddr(strToValidate: userCredentials.email) && isValidPassword(strToVailidate: userCredentials.password)) {
                        
                        print("Email and Passowrd are valid")
                    }
                    else {
                        self.showAlert.toggle()
                    }
                }
                .alert(isPresented: $showAlert, content: { self.alert })
                .font(.title)
                .buttonStyle(.bordered)
                .frame(width:200, height: 100)
            }.frame(maxHeight: .infinity, alignment: .bottom)
        }.background(.gray)
    }
}
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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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: $userCredentials.email)
// 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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading