Many times, we face similar error when declaring custom variables.
Example:
struct ContentView: View {
var body: some View {
header
}
var header: some View {
Image("someimage")
Text("Hello")
}
}
Solution: We can use @ViewBuilder. This macro creates the content as closer and hence avoid us to give this error.
struct ContentView: View {
var body: some View {
header
}
@ViewBuilder
var header: some View {
Image("someimage")
Text("Hello")
}
}
PS: When we are searching for same error in search engine it is taking us to this solution so added this another case to help others.