<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/SectionedFetchRequest",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI21SectionedFetchRequestV"
  },
  "title" : "SectionedFetchRequest"
}
-->

# SectionedFetchRequest

A property wrapper type that retrieves entities, grouped into sections,
from a Core Data persistent store.

```
@MainActor @propertyWrapper @preconcurrency struct SectionedFetchRequest<SectionIdentifier, Result> where SectionIdentifier : Hashable, Result : NSFetchRequestResult
```

## Overview

Use a `SectionedFetchRequest` property wrapper to declare a
[`SectionedFetchResults`](/documentation/SwiftUI/SectionedFetchResults) property that provides a grouped collection of
Core Data managed objects to a SwiftUI view. If you don’t need sectioning,
use [`FetchRequest`](/documentation/SwiftUI/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
[`managedObjectContext`](/documentation/SwiftUI/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`](/documentation/SwiftUI/SectionedFetchRequest/Configuration) structure, either directly or with
a binding.

## Topics

### Creating a fetch request

[`init(sectionIdentifier:sortDescriptors:predicate:animation:)`](/documentation/SwiftUI/SectionedFetchRequest/init(sectionIdentifier:sortDescriptors:predicate:animation:))

Creates a sectioned fetch request based on a section identifier, a
predicate, and reference type sort parameters.

[`init(entity:sectionIdentifier:sortDescriptors:predicate:animation:)`](/documentation/SwiftUI/SectionedFetchRequest/init(entity:sectionIdentifier:sortDescriptors:predicate:animation:))

Creates a sectioned fetch request for a specified entity description,
based on a section identifier, a predicate, and sort parameters.

### Creating a fully configured fetch request

[`init(fetchRequest:sectionIdentifier:animation:)`](/documentation/SwiftUI/SectionedFetchRequest/init(fetchRequest:sectionIdentifier:animation:))

Creates a fully configured sectioned fetch request that uses the
specified animation when updating results.

[`init(fetchRequest:sectionIdentifier:transaction:)`](/documentation/SwiftUI/SectionedFetchRequest/init(fetchRequest:sectionIdentifier:transaction:))

Creates a fully configured sectioned fetch request that uses the
specified transaction when updating results.

### Configuring a request dynamically

[`SectionedFetchRequest.Configuration`](/documentation/SwiftUI/SectionedFetchRequest/Configuration)

The request’s configurable properties.

[`projectedValue`](/documentation/SwiftUI/SectionedFetchRequest/projectedValue)

A binding to the request’s mutable configuration properties.

### Getting the fetched results

[`update()`](/documentation/SwiftUI/SectionedFetchRequest/update())

Updates the fetched results.

[`wrappedValue`](/documentation/SwiftUI/SectionedFetchRequest/wrappedValue)

The fetched results of the fetch request.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)