This modifier on a SwiftUI view compiles fine:
.background(GeometryReader { p in
return Rectangle().opacity(0)
})
(I know I don't need the return, but I'm about to add another line.)
When I add a print
call, it no longer compiles.
.background(GeometryReader { p in
print("hi")
return Rectangle().opacity(0)
})
The error points to background
and says:
Expression type '(_, Alignment) -> some View' is ambiguous without more context
I don't understand why it's confused now about the type of thing passed to .background(...)
. It's got the same clear return
expression as before. How can I fix the code to satisfy the type checker?