Skip to content

Instantly share code, notes, and snippets.

@jaywardell
Created October 24, 2019 16:23
Show Gist options
  • Save jaywardell/425575c30ec98dbb54df75cbe20339a1 to your computer and use it in GitHub Desktop.
Save jaywardell/425575c30ec98dbb54df75cbe20339a1 to your computer and use it in GitHub Desktop.
Creating a View that contains another view builder in SwiftUI
import SwiftUI
struct ContainerView<Content: View>: View {
let content: Content
public init(@ViewBuilder builder: () -> Content) {
self.content = builder()
}
public var body: some View {
content
}
}
// Usage
struct ContainerView_Previews: PreviewProvider {
static var previews: some View {
ContainerView() { Text("hi") }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment