How can I find the number of elements a view stack contains in SwiftUI? Enclosed you can see a concise representation of what I am trying to implement. Mirror didn't work. I can define Content as an array but that doesn't align with what I'm trying to do.
struct HowManyElementsStack<Content: View>: View {
var content: () -> Content
var nofElements: Int
init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
nofElements = Mirror(reflecting: content()).children.count
}
var body: some View {
Text(“There are: \(nofElements) in this view stack") //returns 0 in all cases
}
}