Expected Expression Error Swiftui

i get the expected expression error every time i restart Xcode i have tried numerous times to fix it here is the code

import SwiftUI



struct MainView: View {

    

    var body: some View {

        

        Color(.secondarySystemBackground)

        HStack{



        }

        NavigationView{

            

            

            Text("")

                .navigationTitle("Home")

                

        }

navigationBarItems(trailing:

Button(action: {

print("Hello")

}) {

Image(systemName: "square.and.pencil")

.resizable()

.frame(width: 50, height: 50)



) <- Error Here

            }

        }

}



struct MainView_Previews: PreviewProvider {

    static var previews: some View {

        MainView()

    }

}
Answered by workingdogintokyo in 670714022
you have the ") <- Error Here }" the wrong way around. It should be:

Code Block
navigationBarItems(trailing:
Button(action: {
print("Hello")
}) {
Image(systemName: "square.and.pencil")
.resizable()
.frame(width: 50, height: 50)
}) <- Error not Here

Accepted Answer
you have the ") <- Error Here }" the wrong way around. It should be:

Code Block
navigationBarItems(trailing:
Button(action: {
print("Hello")
}) {
Image(systemName: "square.and.pencil")
.resizable()
.frame(width: 50, height: 50)
}) <- Error not Here

thanks it worked

.package(url: "https://github.com/binarybirds/swift-html", from: "1.6.0");,import Foundation

underlined sections have errors like this. what’s wrong with this?

Here's the corrected code:

import SwiftUI

struct MainView: View {
    var body: some View {
        NavigationView {
            Text("")
                .navigationTitle("Home")
                .navigationBarItems(trailing:
                    Button(action: {
                        print("Hello")
                    }) {
                        Image(systemName: "square.and.pencil")
                            .resizable()
                            .frame(width: 50, height: 50)
                    }
                )
        }
    }
}

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

I've moved the navigationBarItems modifier inside the NavigationView block and added the closing parenthesis for the Button modifier. This should resolve the "Expected expression" error you were encountering.