Michael Long
Mar 6, 2022

--

I was with you up until the point where you wrote a "pilot" switch handler that punted and returned AnyView.

AnyView can mess with how SwiftUI manages view identification and state management past that point. I'd have to play with the code, and I have no doubt the bare-bones sample works, but in a real app I'd be leery of having some update near the root of the view tree triggering a refresh and then losing state further on in subsequent views.

AnyView, IMHO, is a tool of last resort, and shouldn't be used as the foundation of a SwiftUI application.

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

Responses (1)