SwiftUI: Function declares an opaque return type, but has no return statements in its body from which to infer an underlying type

Function declares an opaque return type, but has no return statements in its body from which to infer an underlying type

When does such an error happen?

A view body in SwiftUI goes like

var body: some View {
Text("Hello, World!")
}

The body does not have a return type

var body: some View {
let displayText = "Heyy Swifters !!"
Text(displayText)
}

A conditional body involving multiple views

var body: some View {
if isSwiftyDisplay {
Text("Heyy Swifters!!")
} else {
Text("Hello World!!")
}
}
@ViewBuilder
var
body: some View {
if isSwiftyDisplay {
Text("Heyy Swifters!!")
} else {
Text("Hello World!!")
}
}

The body having multiple views

var body: some View {
Text("Heyy Swifters!!")
Text("Hello World!!")
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store