< How to fix “Ambiguous reference to member 'buildBlock()’” | How to fix “Property declares an opaque return type, but has no initializer expression from which to infer an underlying type” > |
Updated for Xcode 14.2
This error occurs for two reasons. First, you’ve created a view but didn’t actually return it from your view body, like this:
var body: some View {
let name = "Paul"
let message = Text("Hello, \(name)")
}
To make that compile, add return message
:
var body: some View {
let name = "Paul"
let message = Text("Hello, \(name)")
return message
}
The other common reason this happens is if you try to return two views without placing them in a container, like this:
var message: some View {
Text("Hello")
Text("World")
}
To fix this, place your views in a stack or a group, like this:
var message: some View {
VStack {
Text("Hello")
Text("World")
}
}
SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.