Hi I have a for each loop which goes through a struct with values and in this for each loop I am trying to create a toggle for each and each needs its own isOn parameter so in my struct I have added 'isToggleOn' and set it to true but i am getting the following error: Cannot convert value of type 'Bool' to expected argument type 'Binding<Bool>'
and this view gets called by another view which provides it with the Sandwich struct
And i am not sure what the best way to approach this and any help would be appreciated.
import SwiftUI
struct IngredientView: View {
var sandwich: Sandwich
var body: some View {
ForEach(sandwich.ingredients) { ingredient in
HStack {
Text(ingredient.name)
Toggle("", isOn: ingredient.isToggleOn)
.toggleStyle(CheckboxToggleStyle(style: .square))
.foregroundColor(.blue)
}
}
}