I'm trying to pass data to TextField using combine. by creating a data model and using observableObject, but when I use it in textField it shows me the error. Cannot convert value of type 'String' to expected argument type 'Binding< String >'. I'm unable to understand it.
dataModel
struct People: Identifiable {
var id = UUID()
var name: String
var amount: String
}
let peopleData = [
People(name: "A",amount: ""),
People(name: "B",amount: ""),
People(name: "C",amount: "")
]
ObservableObject
import Combine
class PeopleAllData: ObservableObject{
@Published var peopleStore: [People] = peopleData
}
TextField
@ObservedObject var store = PeopleAllData()
List{
ForEach(store.peopleStore){ item in
HStack {
TextField("person Name", text: item.name) //Error:- Cannot convert value of type 'String' to expected argument type 'Binding<String>'
Button(action: {}) {
Image(systemName: "minus.circle")
.foregroundColor(.red)
}
}
}
}
.frame(width: screen.width, height: screen.height)