I can do a static List like
List {
View1()
View2()
}
But how do i make a dynamic list of elements from an array? I tried the followin
Looks like the answer was related to wrapping my view inside of AnyView
struct ContentView : View {
var myTypes: [Any] = [View1.self, View2.self]
var body: some View {
List {
ForEach(0.. AnyView {
switch types[index].self {
case is View1.Type: return AnyView( View1() )
case is View2.Type: return AnyView( View2() )
default: return AnyView(EmptyView())
}
}
With this, i can now get view-data from a server and compose them. Also, they are only instanced when needed.