Earlier quoted context omitted.
From what I understand, SwiftUI uses this so that each "snapshot" of the View tree generated by the app can be intelligently diffed against future snapshots. This helps make rendering more efficient, as well as with things like animations. Consider a simple view like: var body: some View { if someStateBool { Text("True") } else { Text("False") } Suppose that initially, `someStateBool ` evaluates to `true`, and then i…
It's more fundamental than that. Consider: var body : some View { if something { return Image("hi") } else { return Text("hi") } } this function won't even compile because Swift infers different types for the returns (Image vs Text). In order to give the return value a type, the if statement has to be encoded in the type system itself.
Incidentally, if you use `AnyView` liberally you’ll likely see worse automatic animations and degraded performance [ETA: the “degraded performance” claim here appears to have been debunked—see the link below for more info!].