I am trying to create a SwiftUI view where I can pass a view builder. But by using a view builder parameter I cannot change the state. Is this due to the creation in the init method? How can I achieve my expected behaviour?
struct Card_Previews: PreviewProvider {
@State
static var bol: Bool = true
static var previews: some View {
Label(title: { content })
}
// Does not change the value
private static var content: some View {
Button(bol.description) {
bol.toggle()
}
}
}
struct Label<Title>: View where Title: View {
var body: some View {
title
}
let title: Title
public init(@ViewBuilder title: () -> Title) {
self.title = title()
}
}
If something is unclear pleas ask :)