When I try to set show a toggle inside a loop of value from a dictionary, I get very little help from the error message.
If I un-comment the 3 lines of commented code below, trying to add a toggle for each of the properties in the loop, I get the following error:
Cannot convert value of type 'HStack, Text, ConditionalContent)>>' to closure result type '_'
import SwiftUI
struct properties {
var id : Int
var property : String
var isOn : Bool
}
struct ContentView: View {
@State var propertyValues: [properties] = [properties(id: 1, property: "DemoData", isOn: true),
properties(id: 2, property: "ShowLocalEvents", isOn: false)]
var body: some View {
NavigationView {
VStack {
List {
ForEach(propertyValues.identified(by: \.id)) { propertyValue in
HStack {
// Toggle(isOn: propertyValue.isOn) {
// Text("")
// }
Text("\(propertyValue.property)")
if propertyValue.isOn {
Text("On")
} else {
Text("Off")
}
}
}
}
}
}
}
}