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!")
}
}
}
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!")
}