Reputation: 107
I'm trying to apply some navigationBarItems to my View and I've gotten this error - Type '() -> Text' cannot conform to 'View'; only struct/enum/class types can conform to protocols
I've been able to dumb the code down to this. Anyone know what could be causing it?
struct NewEntry: View {
var body: some View {
NavigationView {
VStack {
Text("Hello World")
}
.navigationBarItems(trailing: {
Text("Hello World")
})
}
}
}
Upvotes: 2
Views: 396
Reputation: 20244
.navigationBarItems(trailing:)
takes a View
.
You are providing the View
inside {}
.navigationBarItems(trailing: {
Text("Hello World")
})
.navigationBarItems(trailing: Text("Hello, World"))
SwiftUI
's compiler is a bit dumb, small syntax mistakes causes it to throw weird errors at weird places.
Upvotes: 4