'Selection of nested CoreData List SwiftUI

Im trying to make my List selectable so I can delete or share multiple instances! Im trying to do that, with this method: List(selection: $selection) Here's my code:

struct ContentView: View {
@FetchRequest(entity: Rechnungen.entity(), sortDescriptors: [
    NSSortDescriptor(keyPath: \Rechnungen.datum, ascending: false)
], animation: .default
) var rechnung: FetchedResults<Rechnungen>
   var body: some View {
       //some come where I call:
       ContentListView(rechnung:rechnung)
   }
}
struct ContentListView: View {
@State var selection = Set<Rechnungen>()
var rechnung: FetchedResults<Rechnungen>
   var body: some View {
        List(selection: $selection) {
           ForEach(rechnung) { beleg in
                    //displaying my instances here
            }
        }
    }
}

If I display the EditButton() in my toolbar then I can see the option to select my Instances but I can't select anything.

I guess my @State var selection = Set<Rechnungen>()is wrong. But I can't find anything that works.

Thank you in advance,



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source