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?

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!!")
}

--

--

--

Software Developer(iOS), Speaker & Writer at Swift India

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

iOS Accessibility Labels

5 Skills that iOS developers should focus in 2022

iPad 3 as a Second Display

Tackling UI test execution time imbalance for Xcode parallel testing

‘whiteLarge’ was deprecated in iOS 13.0"

Why hire app development Dubai services for app delivery services?

Private extensions in Swift

Multi-line text input in SwiftUI-SaralGyaan

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
G. Abhisek

G. Abhisek

Software Developer(iOS), Speaker & Writer at Swift India

More from Medium

Fundamental Design Pattern: Strategy

SwiftUI’s EnvironmentValues backported to UIKit

Every iOS developer should know these Xcode tricks

100 Days of SwiftUI Learning — Day 8