SectionedFetchRequest
struct · iOS 15.0+ · SDK 27.1
@MainActor @propertyWrapper @preconcurrency struct SectionedFetchRequest<SectionIdentifier, Result> where SectionIdentifier : Hashable, Result : NSFetchRequestResultA property wrapper type that retrieves entities, grouped into sections, from a Core Data persistent store. Use a `SectionedFetchRequest` property wrapper to declare a ``SectionedFetchResults`` property that provides a grouped collection of Core Data managed objects to a SwiftUI view. If you don't need sectioning, use ``FetchRequest`` instead. Configure a sectioned fetch request with an optional predicate and sort descriptors, and include a `sectionIdentifier` parameter to indicate how to group the fetched results. Be sure that you choose sorting and sectioning that work together to avoid discontiguous sections. For example, you can request a list of earthquakes, composed of `Quake` managed objects that the <doc://com.apple.documentation/documentation/SwiftUI/Loading-and-displaying-a-large-data-feed> sample code project defines to store earthquake data, sorted by time and grouped by date: @SectionedFetchRequest<String, Quake>( sectionIdentifier: \.day, sortDescriptors: [SortDescriptor(\.time, order: .reverse)] ) private var quakes: SectionedFetchResults<String, Quake> Always declare properties that have a sectioned fetch request wrapper as private. This lets the compiler help you avoid accidentally setting the property from the memberwise initializer of the enclosing view. The request infers the entity type from the `Result` type that you specify, which is `Quake` in the example above. Indicate a `SectionIdentifier` type to declare the type found at the fetched object's `sectionIdentifier` key path. The section identifier type must conform to the <doc://com.apple.documentation/documentation/Swift/Hashable> protocol. The example above depends on the `Quake` type having a `day` property that's either a stored or computed string. Be sure to mark any computed property with the `@objc` attribute for it to function as a section identifier. For best performance with large data sets, use stored properties. The sectioned fetch request and its results use the managed object context stored in the environment, which you can access using the ``EnvironmentValues/managedObjectContext`` environment value. To support user interface activity, you typically rely on the <doc://com.apple.documentation/documentation/CoreData/NSPersistentContainer/viewContext> property of a shared <doc://com.apple.documentation/documentation/CoreData/NSPersistentContainer> instance. For example, you can set a context on your top-level content view using a shared container that you define as part of your model: ContentView() .environment( \.managedObjectContext, QuakesProvider.shared.container.viewContext) When you need to dynamically change the section identifier, predicate, or sort descriptors, access the request's ``SectionedFetchRequest/Configuration`` structure, either directly or with a binding.
Members (0)
This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.
Skipped declarations
6 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
SectionedFetchRequest.wrappedValue
The containing type needs Swift generic type arguments. (no canonical witness for Result)
SectionedFetchRequest.projectedValue
The containing type needs Swift generic type arguments. (no canonical witness for Result)
SectionedFetchRequest.update()
The containing type needs Swift generic type arguments. (no canonical witness for Result)
SectionedFetchRequest.init(entity:sectionIdentifier:sortDescriptors:predicate:animation:)
This declaration needs Swift generic type arguments. (no canonical witness for Result)
SectionedFetchRequest.init(fetchRequest:sectionIdentifier:animation:)
This declaration needs Swift generic type arguments. (no canonical witness for Result)
SectionedFetchRequest.init(fetchRequest:sectionIdentifier:transaction:)
This declaration needs Swift generic type arguments. (no canonical witness for Result)