< 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 12.0
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 body: some View {
Text("")
Text("")
}
To fix this, place your views in a stack or a group, like this:
var body: some View {
VStack {
Text("")
Text("")
}
}
SPONSORED Would you describe yourself as knowledgeable, but struggling when you have to come up with your own code? Fernando Olivares has a new book containing iOS rules you can immediately apply to your coding habits to see dramatic improvements, while also teaching applied programming fundamentals seen in refactored code from published apps.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.