Coredata entities : Type (with attribute: "nom") who own many Sujet (with attribute: "nom") (one-to-many relationship)
This works for me :
List of Sujets, sectioned by Types
struct SujetsSectionedListByType: View {
// MARK: - Properties
@SectionedFetchRequest(
sectionIdentifier: \Sujet.type?.nom,
sortDescriptors: [
SortDescriptor(\Sujet.type?.nom, order: .forward),
SortDescriptor(\Sujet.nom, order: .forward)
])
private var sujets: SectionedFetchResults<String?, Sujet>
@Binding var selectedSujet: Sujet?
// MARK: - Body
var body: some View {
List(selection: $selectedSujet) {
ForEach(sujets) { section in
Section(header: Text(section.id ?? "")) {
ForEach(section) { sujet in
NavigationLink(destination: SujetDetail(sujet: sujet, selectedSujet: $selectedSujet), tag: sujet, selection: $selectedSujet) {
SujetListItem(sujet: sujet)
}
}
}
}
}
.frame(minWidth: ListsMinWidth)
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: