I'm trying to adjust a list so that it can have multiple selection.
It works when I use hard coded data, but when I try and use it with core data, the option to edit the list doesn't bring the checkboxes up.
Working code
struct DIMTest: Identifiable {
let id = UUID()
let name: String
}
struct DimTypeListView: View {
let contacts = [
DIMTest(name: "John"),
DIMTest(name: "Alice"),
DIMTest(name: "Bob")
]
// 2
@State private var multiSelection = Set<DIM>()
var body: some View {
NavigationView {
VStack {
// 3
List(contacts, selection: $multiSelection) { contact in
Text(contact.name)
}
Text("\(multiSelection.count) selections")
}
.navigationTitle("Contacts")
.toolbar {
// 4
EditButton()
}
}
}
}
but when I adjust the code to the below to load from core data, I don't get the checkboxes
@SectionedFetchRequest var dims: SectionedFetchResults<Bool, DIM>
init(dType: DimType) {
_dims = SectionedFetchRequest<Bool, DIM>(
sectionIdentifier: \.favourite,
sortDescriptors: [NSSortDescriptor(keyPath: \DIM.favourite, ascending: false), NSSortDescriptor(keyPath: \DIM.name, ascending: true)],
predicate: NSPredicate(format: "dimType = %@", dType)
)
}
@State private var multiSelection = Set<DIM>()
var body: some View {
VStack {
List(dims, selection: $multiSelection) { section in
Section() {
ForEach(section) { dim in
Text("Name")
}
}
}
Text("\(multiSelection.count) selections")
}
.navigationTitle("DIMs")
.toolbar {
EditButton()
}
}
It shows the correct number of entries, but can't be selected
If i add an onDelete, i get the delete options but only want to be able to select, not delete