4 ms·
That problem could have been resolved via type erasure (either via `AnyView`, or, if SwiftUI had been designed differently, by having the `body` property be of
by jumhyn 6y ago
That problem could have been resolved via type erasure (either via `AnyView`, or, if SwiftUI had been designed differently, by having the `body` property be of type `View` rather than `some View`). In fact, opaque types (a la `some View`) were motivated by SwiftUI so that the type information could be preserved to enable the necessary optimizations/animations, without requiring users/library authors to write out/expose the complex type signatures that can arise from even simple view hierarchies.
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!].
- LeoNatan25 6y agoDespite what is claimed about AnyView, this has for the most part been proven wrong. AnyView is just as fast, if not faster. https://nalexn.github.io/anyview-vs-group/ https://nalexn.github.io/anyview-vs-group/ In fact, Apple themselves use AnyView internally for many of their controller presentations (such as sheets and pushed controllers).
- jumhyn 6y agoGreat article! Glad to have that misconception cleared up.