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.