Why, in SwiftUI, the body gets called twice when we use a VStack
?
Example without a VStack
:
struct ContentView: View {
var body: some View {
Text("Hello World")
}
}
By placing a breaking point at Text("Hello World")
, I can see the function body
runs a single time, as I expected.
If I slightly change this code by including a VStack
, the situation changes:
struct ContentView: View {
var body: some View {
VStack { Text("Hello World") }
}
}
Now, if I place the breakpoint at the same line, I can see the function body
is called twice.
Why exactly does this happen? Why just by the inclusion of a VStack
SwiftUI needs to run body
again?