Hi,
I have a view that takes an optional binding boolean variable. I'd like to pass a variable to it from certain views only. The problem I'm having is when I pass a variable, I get the error "Cannot convert value of type 'Binding<Bool>' to expected argument type 'Binding<Bool?>'", and when I don't, I get the error "Missing argument for parameter 'toggle' in call". Below Is the code I have. Thank you.
Heading(text: "Heading1") // error: Missing argument for parameter 'toggle' in call
Heading(text: "Heading2", toggle: $newEntry) // Cannot convert value of type 'Binding<Bool>' to expected argument type 'Binding<Bool?>'
struct Heading: View {
@State var text: String
@Binding var toggle: Bool?
var body: some View {
VStack {
Spacer()
.frame(height: 25)
HStack {
Text(text)
.font(.system(size: 36))
Spacer()
if text == "str" {
Button(action: { toggle!.toggle() }) {
Image(systemName: "plus")
.foregroundColor(.black)
.font(.system(size: 36))
}
}
}
Spacer()
.frame(height: 25)
}
}
}