Trailing closure passed to parameter of type 'Visibility' that does not accept a closure

Hi All, I'm quite new to swift and am wondering why I am receiving a "Trailing closure passed to parameter of type 'Visibility' that does not accept a closure" error on the .toolbar{ line

I Have Supplied My Code Below

Thanks in Advance,

Josh


struct HomeView: View {

    var body: some View {

        Text("Home")

            .toolbar{

                ToolbarItem(placement: .navigationBarLeading)

                Button(action: NavigationLink(destination: AccountView()), label: Image(systemName: "gearshape"))

                ToolbarItem(placement: .principal) { Text("Welcome").font(.title)

                }

                ToolbarItem(placement: .navigationBarTrailing)

                Button(action: NavigationLink(destination: AccountView()), label: Image(systemName: "person.circle"))

            }

            .navigationBarTitleDisplayMode(.inline)

    }

}

struct HomeView_Previews: PreviewProvider {

    static var previews: some View {

        HomeView()

    }

}```

Answered by The-Wolf in 820725022

I was missing the { from ToolbarItem

var body: some View {
        NavigationStack {
            Text("Home")
                .toolbar {
                    ToolbarItem(placement: .navigationBarLeading) {
                        NavigationLink {
                            AccountView()
                        } label: {
                            Image(systemName: "gearshape")
                        }

                    }
                }
        }
    }
Accepted Answer

I was missing the { from ToolbarItem

var body: some View {
        NavigationStack {
            Text("Home")
                .toolbar {
                    ToolbarItem(placement: .navigationBarLeading) {
                        NavigationLink {
                            AccountView()
                        } label: {
                            Image(systemName: "gearshape")
                        }

                    }
                }
        }
    }
Trailing closure passed to parameter of type 'Visibility' that does not accept a closure
 
 
Q