无法将类型 'Binding<_>' 的值转换为预期的参数类型 'Binding<Card>'
Cannot convert value of type 'Binding<_>' to expected argument type 'Binding<Card>'
我正在尝试创建到 FetchedResults
项的绑定,错误出现在 $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])
}
}
}
}
}
更改绑定到 ObservedObject 编译并且似乎工作正常,虽然我觉得我通过创建一个新的 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)
}
}
}
}
}
我正在尝试创建到 FetchedResults
项的绑定,错误出现在 $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])
}
}
}
}
}
更改绑定到 ObservedObject 编译并且似乎工作正常,虽然我觉得我通过创建一个新的 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)
}
}
}
}
}