Posts

Post not yet marked as solved
0 Replies
241 Views
Hello, I would like to design a generic view such that it could be initialized by a view builder closure. Let us say, I have something like this. struct Cell<Subject>: View where Subject: View {       let subject: Subject       init(         @ViewBuilder subject: () -> Subject       ) {         self.subject = subject()       }       var body: some View {         subject       }     } If I have to use it in previews, I would do something like this. static var previews: some View { VStack {       Cell<Text> {         Text("ASASD")       }        Cell<Button> {         Button {} label: { Text("ASDSAD") }       }  } } However, I have a parent VM which requires a collection of such generic cells. VM { var cells: [Cell<AnyGenericType>] } What is the best way to make such collection. I am okay with casting them to AnyView but I cannot understand how I would make above possible. My idea is to utilize this collection in the ParentView.
Posted Last updated
.