0

I am trying to create a binding to a FetchedResults item, error is on $items[i]:

struct NavView: View {   
    @Binding var item : Card

    ...
}

struct ContentView: View {
private var items: FetchedResults<Card>

var body: some View {
    List {
        ForEach(items.indices, id:\.self) { i in
            NavigationLink {
                NavView(item: $items[i])
            }
        }
    }
}
}
  • 1
    Is that really a topic that you cannot find an aswer for by running a simple search engine search? – El Tomato Sep 29 '21 at 04:50
  • 2
    The closest link I found in Google was https://stackoverflow.com/questions/58724301/cannot-convert-value-of-type-bindingint-to-expected-argument-type-binding which does not really seem to answer the question – Makoto Niijima Sep 29 '21 at 05:00

1 Answers1

0

Changing the Binding to ObservedObject compiles and seems to work properly, although I feel like I'm violating single source of truth policy by creating a new ObservedObject.

struct NavView: View {   
    @ObservedObject var item : Card

    ...
}

struct ContentView: View {
private var items: FetchedResults<Card>

var body: some View {
    List {
        ForEach(items) { item in
            NavigationLink {
                NavView(item: item)
            }
        }
    }
}
}