Some Views in SwiftUI, like VStack and HStack support having multiple views as children, like this:
VStack {
Text("hello")
Text("world")
}
From what I gather, they use ViewBuilder to make this possible as explained here.
How can we use @ViewBuilder for creating our own Views which support multiple children? For example, let's say that I want to create a Layout View which accepts arbitrary children -- something like this:
struct Layout : View {
let content: Some View
var body : some View {
VStack {
Text("This is a layout")
content()
}
}
}
Any idea how to implement this pattern in SwiftUI?