struct NavLinkLabel: View {
var text: String
var body: some View {
HStack {
Text(text)
Spacer()
Image(systemName: "chevron.right")
}
.padding()
.border(.bar)
}
}
func lbl(_ text: String) -> () -> some View {
return {
NavLinkLabel(text: text) //ERROR
}
}
This gives me an error on the marked line:
Cannot convert value of type 'NavLinkLabel' to closure result type 'some View'
This is despite the fact that NavLinkLabel conforms to the View protocol.
If I replace the offending line with NavLinkLabel(text: text).body, I get this:
Cannot convert value of type 'some View' (type of 'NavLinkLabel.body') to closure result type 'some View' (result of 'lbl')
Why can't it convert a conforming type, or an even an opaque type, to an opaque type of the same protocol? I don't doubt there's a better way to do this anyway, but I'm just experimenting and wondering why this doesn't work.