Help with "Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure."

Hello,

Apologies if I don't follow protocol. This is my first time asking a question.

I'm enjoying discovering Swift.

I'm getting tan error after Form { and wonder if you might know how to resolve it.

After Form { I receive the following error: "Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure."

What am I doing wrong? Below is the entire RegisterView file. Thank you in advance for any assistance.
How will I receive your response? I've not entered my email address anywhere?

Here at 17:39 shows what it should look like: https://www.youtube.com/watch?v=pAB1tMH6TFc

Lorna

import SwiftUI

struct RegisterView: View { @StateObject var viewModel = RegisterView_ViewModel()

var body: some View {
    VStack {
        //Header
        HeaderView(title: "Register",
                   subtitle: "Start organizing",
                   angle: -15,
                   background: .blue)
        
        Form {
            TextField("Full Name", text: $viewModel.name)
                .textFieldStyle(DefaultTextFieldStyle())
                .autocorrectionDisabled()
            
            TextField("Email Address", text: $viewModel.email)
                .textFieldStyle(DefaultTextFieldStyle())
                .autocapitalization(.none)
                .autocorrectionDisabled()
            
            SecureField("Password", text: $viewModel.password)
                .textFieldStyle(DefaultTextFieldStyle())
       
       
            TLButton(
                title: "Create Account",
                background: .green
            ) {
                viewModel.register()
            }
            .padding()
        }
        .offset(y: -50)
        
        Spacer()
    }
}

}

struct RegisterView_Previews: PreviewProvider { static var previews: some View { RegisterView() } }

Thank you in advance for your help.

Lorna

Replies

welcome to the forum! Nothing jumps out at me as obviously wrong in the code you posted. The code is incomplete, so it can't be simply copied and pasted into someone else's project so they can maybe duplicate the error you see. In situations like this, where it looks like the compiler is complaining of an error in the Form closure, I would try commenting out different elements of the Form to figure out what exactly it is complaining about. My hunch would be a typo in TLButton, which you have not shown.

You asked how you receive a response. You can 'watch' a thread, by clicking the bell icon on the top right of a thread. I think the forum may now automatically email you when there's a new response to a thread that you started.

Incidentally, if you want to share a YouTube video at a particular point in time, you can use the Share button on the YouTube button to generate a link. On desktop at least, there is an option to "start at", which appends a time to the URL.

Thank you so much for taking your time to try to help. I really appreciate it.

The code is part of a bigger project with a number of pages. I'm on Lesson 6. Everything was perfect up until now. So, I'm stuck. I commented out sections of what I sent but still not working.

Re YouTube, thank you!! Great!

I did not include TLButton because there were no errors indicated. Here it is.

import SwiftUI

struct TLButton: View { let title: String let background: Color let action: () -> Void

var body: some View {
    Button {
        action()
    } label: {
        ZStack {
            RoundedRectangle(cornerRadius: 10)
                .foregroundColor(background)
            
            Text(title)
                .foregroundColor(Color.white)
                .bold()
        }
    }
}

}

struct TLButton_Previews: PreviewProvider { static var previews: some View { TLButton(title: "Value", background: .red) { // Action } } }

When I comment out a section of the view. The build is successful but then it will not show what it should show. Instead, I see this. TODO`static TODOApp.$main(): 0x1055097a0 <+0>: pushq %rbp 0x1055097a1 <+1>: movq %rsp, %rbp 0x1055097a4 <+4>: pushq %r13 0x1055097a6 <+6>: pushq %rax 0x1055097a7 <+7>: callq 0x1055097d0 ; lazy protocol witness table accessor for type TODO.TODOApp and conformance TODO.TODOApp : SwiftUI.App in TODO at <compiler-generated> 0x1055097ac <+12>: movq %rax, %rsi 0x1055097af <+15>: leaq 0x8995b2(%rip), %r13 ; type metadata for TODO.TODOApp 0x1055097b6 <+22>: movq %r13, %rdi 0x1055097b9 <+25>: callq 0x105badae4 ; symbol stub for: static SwiftUI.App.main() -> () -> 0x1055097be <+30>: addq $0x8, %rsp 0x1055097c2 <+34>: popq %r13 0x1055097c4 <+36>: popq %rbp 0x1055097c5 <+37>: retq

What is not visible here is what is printed in red is the following: "Thread 1: "The default FirebaseApp instance must be configured before the default Authinstance can be initialized. One way to ensure this is to call FirebaseApp.configure() in the App Delegate's application(_:didFinishLaunchingWithOptions:) (or the @main struct's initializer in SwiftUI)."

Please show some more code:

  • TLButton
  • HeaderView
  • RegisterView_ViewModel

Also show the exact error message and where it shows

So you made some progress!

You said "When I comment out a section of the view. The build is successful..." - what section? Initially, you were asking about a build problem. That original build problem was caused by something in that commented-out section. Figure out what exactly the problem is.

Sorry, can't help you with Firebase. That may be caused by commenting out some of the code to fix your build error.

@LornaL Let us stay with the original code, otherwise it will be impossible to understand and fix the issue.

Where exactly do you see the error message in code ? On this line ?

        Form {

Elsewhere ?

I tested your code (replacing calls to model such as $viewModel.password by simple calls to State var as $password. It works.

Is the code you posted the complete code of the body ? You may have forgotten or misplaced some curly braces which confuses the compiler.

There are examples of such errors because of this: https://www.hackingwithswift.com/forums/swiftui/error-message-trailing-closure-passed-to-parameter-of-type-formstyleconfiguration-that-does-not-accept-a-closure/17169

Hello Claude31,

The error is on the same line as Form {

All the code and curly braces are included.

I am not sure if I understood exactly what you had in mind. I tried this but had the same issue. Not sure why the error message does not copy here, but it is exactly the same as before immediately after Form {

Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure In the box at the bottom left: I see :

Exception NSException * "The default FirebaseApp instance must be configured before the default Authinstance can be initialized. One way to ensure this is to call FirebaseApp.configure() in the App Delegate's application(_:didFinishLaunchingWithOptions:) (or the @main struct's initializer in SwiftUI)." 0x0000600003837810

and

self @thin TODO.TODOApp.Type TODO.TODOApp

FYI I have another file called RegisterView_ViewModel

import SwiftUI

struct RegisterView: View { //@StateObject var viewModel = RegisterView_ViewModel() @State var viewModel = RegisterView_ViewModel()

var body: some View {
    VStack {
        //Header
        HeaderView(title: "Register",
                   subtitle: "Start organizing",
                   angle: -15,
                   background: .blue)
        
        Form {
            
            TextField("Full Name", text: $viewModel.name)
            //TextField("Full Name", text: $viewModel.name)
                .textFieldStyle(DefaultTextFieldStyle())
                .autocorrectionDisabled()
            TextField("Email Address", text: $viewModel.email)
            //TextField("Email Address", text: $viewModel.email)
                .textFieldStyle(DefaultTextFieldStyle())
                .autocapitalization(.none)
                .autocorrectionDisabled()
            
            SecureField("Password", text: $viewModel.password)
            //SecureField("Password", text: $viewModel.password)
                .textFieldStyle(DefaultTextFieldStyle())
       
       
            TLButton(
                title: "Create Account",
                background: .green
            ) {
                viewModel.register()
            }
            .padding()
        }
        .offset(y: -50)
        
        Spacer()
         
    }
}

}

struct RegisterView_Previews: PreviewProvider { static var previews: some View { RegisterView() } }

Is this what is was supposed to look like or did I mess up?

Lorna

Exception NSException * "The default FirebaseApp instance must be configured before the default Authinstance can be initialized. One way to ensure this is to call FirebaseApp.configure() in the App Delegate's application(_:didFinishLaunchingWithOptions:) (or the @main struct's initializer in SwiftUI)." 0x0000600003837810

Could you show the code of either @main or didFinishLaunchingWithOptions ?

Problem with SwitUI is that it often reports errors which are hard to undesrtand because the line where they are reported is not where the error occurs but where the compiler finally gave up…

Hello Claude 31,

I have two MainView files:

This is MainView.swift

import SwiftUI

struct MainView: View { @StateObject var viewModel = MainView_ViewModel()

var body: some View {
    if viewModel.isSignedIn, !viewModel.currentUserId.isEmpty {
        // signed in state
        ToDoListView()
        
    } else {
        LoginView()
        
    }
}

}

struct MainView_Previews: PreviewProvider { static var previews: some View { MainView() } }

This is MainView_ViewModel.swift

import FirebaseAuth import Foundation

class MainView_ViewModel: ObservableObject { @Published var currentUserId: String = "" private var handler: AuthStateDidChangeListenerHandle?

// when user signs in or out this published will be triggered and update oru view

// if we have a user it means they are signed in
// nil = not signed in

init() {
    self.handler = Auth.auth().addStateDidChangeListener { [weak self] _, user in
        DispatchQueue.main.async {
            self?.currentUserId = user?.uid ?? ""
        }
    }
}

public var isSignedIn: Bool {
    return Auth.auth().currentUser != nil
}

}

Thank you.

Lorna

  • Hello,

    I don't know where to put it. Tried a number of locations, but get different error messages e.g. "Type 'Void' cannot confirm to 'View'. Where should I place FirebaseApp.configure()?

    Thank you for any suggestions.

Add a Comment

You do not call FirebaseApp.configure(), which is what the error message advises you to do…

  • Hello, I don't know where to put it. Tried a number of locations, but get different error messages e.g. "Type 'Void' cannot confirm to 'View'. Where should I place FirebaseApp.configure()? Thank you for any suggestions.

Add a Comment