SwiftUI How to iterate through views passed using init of viewBuilder

Viewed 308

I've seen in here that in SwiftUI it is possible to define a view as

struct Passthrough<Content>: View where Content: View {

    let content: () -> Content

    init(@ViewBuilder content: @escaping () -> Content) {
        self.content = content
    }

    var body: some View {
        content()
    }

}

And to use it as

Passthrough {
    Text("one")
    Text("two")
    Text("three")
}

Passthrough will just display all 3 Text elements without doing anything to them.

How can I "capture" each of 3 Views individually (iterate over them all) and do something to them in Passthrough? Let's say making each Text have different font size?

Any way I can perform ForEach on the elements passed to Passthrough?

0 Answers
Related