UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Don't understand why I get the error: Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure

Forums > SwiftUI

I have these @AppStorage settings and the related code to bind them and it works fine:

@AppStorage("settingsToken") private var settingsToken: String = ""
    @AppStorage("settingsUser") private var settingsUser: String = ""
    @AppStorage("settingsSlug") private var settingsSlug: String = ""

    ...
    ...

    Text("Token")
                    .font(.system(size: 17, weight: .regular, design: .rounded))
                    .foregroundColor(settingsAccentColor)
                TextField("Saved Token", text: $settingsToken)

                Text("User")
                    .font(.system(size: 17, weight: .regular, design: .rounded))
                    .foregroundColor(settingsAccentColor)
                TextField("Saved User", text: $settingsUser)

                Text("Slug")
                    .font(.system(size: 17, weight: .regular, design: .rounded))
                    .foregroundColor(settingsAccentColor)
                TextField("Saved Slug", text: $settingsSlug)

But if I add a new @AppStorage...

    @AppStorage("settingsLogo") private var settingsLogo: String = ""

...
...

                Text("Welcome logo")
                    .font(.system(size: 17, weight: .regular, design: .rounded))
                    .foregroundColor(settingsAccentColor)
                TextField("Logo", text: $settingsLogo)

I get a compile error: Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure, on the form of the NavigationView

var body: some View {

        NavigationView {
            Form {

Removing the following line prevents the compile error but clealy I need this:

                TextField("Logo", text: $settingsLogo)

I really can't see what difference adding this new @AppStorage which is exactly the same as the other does.

Note that settingsLogo will be a URL of an image, so i'm using a String.

1      

Do you have anything other then these in the Form? Just looking at your code you have 8 views already if you have more then 2 other you will go over the 10 view limit. Try putting TOKEN, USER and SLUG in a Group enclosure.

1      

It helps everyone figure out what's going on with your code if you post it in a coherent fashion, rather than in pieces that don't connect up to something that makes sense.

1      

Thank you @NigelGee. Exactly, I totally forgot about the group 10 limit. (proviso : i'm 5 weeks into my swift learning, there's a lot to remember)

1      

If that the case I would make a new SwiftUI View and put this in

struct MyTextField: View {
    let title: String
    @Binding var text: String

    var body: some View {
        VStack(alignment: .leading) {
            Text(title)
                .font(.system(size: 17, weight: .regular, design: .rounded))
                .foregroundColor(.accentColor)

            TextField("Enter \(title)", text: $text) // changed from "Saved ..." as this is placeholder and will only see it if the binding is empty
        }
    }
}

struct MyTextField_Previews: PreviewProvider {
    static var previews: some View {
        MyTextField(title: "Logo", text: .constant(""))
    }
}

Then you can use it

struct ContentView: View {
    @AppStorage("settingsToken") private var settingsToken: String = ""
    @AppStorage("settingsUser") private var settingsUser: String = ""
    @AppStorage("settingsSlug") private var settingsSlug: String = ""
    @AppStorage("settingsLogo") private var settingsLogo: String = ""

    var body: some View {
        VStack {
            MyTextField(title: "Token", text: $settingsToken)
            MyTextField(title: "User", text: $settingsUser)
            MyTextField(title: "Slug", text: $settingsSlug)
            MyTextField(title: "Logo URL", text: $settingsLogo)
        }
        .padding()
    }
}

So go from eight Views to four

PS if a question is SOVLED then if you click the checkmark in the bottom right corner.

1      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.