I am getting the following error when I try to bind to a nested property of an observed object from Core Data: Cannot convert value of type 'Binding<String?>' to expected argument type 'Binding<String>'
Below is a simplified overview:
Parent.swift
@FetchRequest(
sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)],
animation: .default)
private var items: FetchedResults<Item>
var body: some View {
NavigationView {
List {
ForEach(items) { item in
Cell(showing: item)
}
// ...
Cell.swift
struct Cell: View {
@ObservedObject var item: Item
init(showing: Item) {
self.item = showing
}
var body: some View {
TextField("Name", text: $item.name) // <-- error shows for this line
// ...
Why does this show an error? How can I create a two-way binding on this textfield with a value stored using Core Data?