I have a simple CardView
container that gets a view in its initializer.
struct CardView<Content: View>: View {
@ViewBuilder var content: Content
var body: some View {
content
.background(Color.green)
.cornerRadius(20)
}
}
When I use it in a view body it works ✅:
struct ScreenView: View {
var body: some View {
CardView {
Text("Hello!")
.padding()
}
}
}
but when I try to keep a reference to the view I get an error:
let card = CardView {
Text("Hello!")
.padding()
}