ResultsSection
A section of fetched results grouped by a common section key path value.
Declaration
struct ResultsSection<Element, SectionTitle> where Element : PersistentModel, SectionTitle : HashableOverview
Each section represents a group of elements that share the same value for the sectionBy key path used at creation.
You access sections by iterating a SectionedResults value returned by a sectioned @Query. Each section conforms to RandomAccessCollection — iterate it directly to access its elements, and use title (or id) to access the section grouping value.
@Query(sort: \.name, sectionBy: \.category)
var items: SectionedResults<Item, String>
ForEach(items) { section in
Section(section.title) { // "Work", "Personal", …
ForEach(section) { item in … } // Item elements
}
}