7

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?

3
  • Would like to know this as well... Seems to be impossible Commented Oct 30, 2020 at 17:24
  • Just linking the 2 questions together. This could work if casting to View worked. Commented Feb 20, 2021 at 18:10
  • linking question: stackoverflow.com/questions/64238485/… Commented Mar 2, 2023 at 3:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.