< 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 13.3
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 Fernando's book will guide you in fixing bugs in three real, open-source, downloadable apps from the App Store. Learn applied programming fundamentals by refactoring real code from published apps. Hacking with Swift readers get a $10 discount!
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.