using array[struct] with @Binding in ForEach

the error is above ,AccountItem is a struct type implements Identifiable

Your title says

@Binding in ForEach

But your code uses List, not ForEach

Please show more code (and as Text, not only screen shot).

A few questions:

  • why do you need a Binding here ? You don't modify accountItems in thais view.
  • How is AccountItemView defined ? If you have an forDisplay var declared, you should call
AccountItemView(forDisplay: accountItem)

So, missing more context, just a guess. Try something like this:

struct AccountListView: View {  
    @Binding var accountItems: [AccountItem]
    
    var body: some View {
        List(accountItems, id: \.self) { accountItem in AccounItemView(forDisplay: accountItem) }  // <<-- id  \.self here
    }
}

With ForEach, you should have:

            ForEach(accountItems, id: \.self) { item in AccounItemView(forDisplay: item) }

But I suspect your Binding to be more @State, and Binding being inside AccounItemView

Then you should have code like this:

struct AccounItemView: View {
    @Binding var forDisplay: AccountItem
    
    var body: some View {
        Text("\(forDisplay.someProperty)")
    }
}

struct AccountListView: View {  
    @State var accountItems: [AccountItem]
    
    var body: some View {
            List($accountItems, id: \.self) { $item in AccounItemView(forDisplay: $item) }
            // or, with ForEach: ForEach($accountItems, id: \.self) { $item in AccounItemView(forDisplay: $item) }
    }
}
using array[struct] with &#64;Binding in ForEach
 
 
Q