6

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?

Markon
  • 741
  • 8
  • 23
  • Would like to know this as well... Seems to be impossible – leonboe1 Oct 30 '20 at 17:24
  • Just linking the 2 questions together. This could work if [casting to `View`](https://stackoverflow.com/q/59608417/4420543) worked. – andras Feb 20 '21 at 18:10
  • linking question: https://stackoverflow.com/questions/64238485/how-to-loop-over-viewbuilder-content-subviews-in-swiftui – pkamb Mar 02 '23 at 03:52

0 Answers0