Lately I’ve been challenging myself to declare switch statement in SwiftUI, or in a more generalized way, execute any anonymous function that can return a View
Use Switch and Case views
Note that this approach does not work yet, as TupeView should support variadic number of contents, and also T.RawValue needs to conform to Equatable in order to check the cases.
Also in Switch statement, Content can’t be inferred
enumAnimal: String{ case cat case dog case mouse }
structMakeView: View{ let make: () -> AnyView
var body: some View { make() } }
structUseMakeView: View{ let animal: Animal = .cat
var body: some View { MakeView { switchself.animal { case .cat: returnText("cat").erase() case .dog: returnText("dog").erase() case .mouse: returnText("mouse").erase() } } } }