Can I put a swiftUI container's content in a func/var/let?

I'm trying to find a syntactically correct way to put the contents of a Container in a separate variable (or function). Can anyone steer me in the right direction? thanks, in advance, mike

struct ContentView: View {
    var body: some View {
        VStack(content: containerContent)
        .padding()
    }

    var containerContent: () -> Content {
        return {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundStyle(.tint)
            Text("Hello, world!")
        }
    }
}
Answered by Claude31 in 772650022

I tried with AnyView but could not make it. https://www.swiftbysundell.com/articles/avoiding-anyview-in-swiftui/

So I did this, not sure that's what you are looking for:

struct ContentView: View {
    var body: some View {
        VStack {
            containerContent
        }
        .padding()
    }

@ViewBuilder var containerContent : some View {
    Image(systemName: "globe")
        .imageScale(.large)
        .foregroundStyle(.tint)
    Text("Hello, world!")
}
Accepted Answer

I tried with AnyView but could not make it. https://www.swiftbysundell.com/articles/avoiding-anyview-in-swiftui/

So I did this, not sure that's what you are looking for:

struct ContentView: View {
    var body: some View {
        VStack {
            containerContent
        }
        .padding()
    }

@ViewBuilder var containerContent : some View {
    Image(systemName: "globe")
        .imageScale(.large)
        .foregroundStyle(.tint)
    Text("Hello, world!")
}
Can I put a swiftUI container's content in a func/var/let?
 
 
Q