Created
October 24, 2019 16:23
-
-
Save jaywardell/425575c30ec98dbb54df75cbe20339a1 to your computer and use it in GitHub Desktop.
Creating a View that contains another view builder in SwiftUI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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