SectionedFetchResults.Section
A collection of fetched results that share a specified identifier.
Declaration
@MainActor @preconcurrency struct SectionOverview
Examine a Section instance to find the entities that satisfy a SectionedFetchRequest predicate, and that have a particular property with the value stored in the section’s id parameter. You specify which property by setting the fetch request’s sectionIdentifier parameter during initialization, or by modifying the corresponding SectionedFetchResults instance’s sectionIdentifier property.
Obtain specific sections by treating the fetch results as a collection. For example, consider the following property declaration that fetches Quake managed objects that the Loading and Displaying a Large Data Feed sample code project defines to store earthquake data:
@SectionedFetchRequest<String, Quake>(
sectionIdentifier: \.day,
sortDescriptors: [SortDescriptor(\.time, order: .reverse)]
)
private var quakes: SectionedFetchResults<String, Quake>Get the first section using a subscript:
let firstSection = quakes[0]Alternatively, you can loop over the sections to create a list of sections.
ForEach(quakes) { section in
Text("Section \(section.id) has \(section.count) elements")
}The sections also act as collections, which means you can use elements like the count property in the example above.