<!--
{
  "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/FetchRequest/Configuration",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI12FetchRequestV13ConfigurationV"
  },
  "title" : "FetchRequest.Configuration"
}
-->

# FetchRequest.Configuration

The request’s configurable properties.

```
@MainActor @preconcurrency struct Configuration
```

## Overview

You initialize a [`FetchRequest`](/documentation/SwiftUI/FetchRequest) with an optional predicate and
sort descriptors, either explicitly or using a configured
<doc://com.apple.documentation/documentation/CoreData/NSFetchRequest>.
Later, you can dynamically update the predicate and sort
parameters using the request’s configuration structure.

You access or bind to a request’s configuration components through
properties on the associated [`FetchedResults`](/documentation/SwiftUI/FetchedResults) instance.

### Configure using a binding

Get a [`Binding`](/documentation/SwiftUI/Binding) to a fetch request’s configuration structure
by accessing the request’s [`projectedValue`](/documentation/SwiftUI/FetchRequest/projectedValue), which you
do by using the dollar sign (`$`) prefix on the associated
results property. For example, you can create a request for `Quake`
entities — a managed object type that the
<doc://com.apple.documentation/documentation/SwiftUI/loading-and-displaying-a-large-data-feed>
sample code project defines — that initially sorts the results by time:

```
@FetchRequest(sortDescriptors: [SortDescriptor(\.time, order: .reverse)])
private var quakes: FetchedResults<Quake>
```

Then you can bind the request’s sort descriptors,
which you access through the `quakes` result, to those
of a [`Table`](/documentation/SwiftUI/Table) instance:

```
Table(quakes, sortOrder: $quakes.sortDescriptors) {
    TableColumn("Place", value: \.place)
    TableColumn("Time", value: \.time) { quake in
        Text(quake.time, style: .time)
    }
}
```

A user who clicks on a table column header initiates the following
sequence of events:

1. The table updates the sort descriptors through the binding.
2. The modified sort descriptors reconfigure the request.
3. The reconfigured request fetches new results.
4. SwiftUI redraws the table in response to new results.

### Set configuration directly

If you need to access the fetch request’s configuration elements
directly, use the [`nsPredicate`](/documentation/SwiftUI/FetchedResults/nsPredicate) and
[`sortDescriptors`](/documentation/SwiftUI/FetchedResults/sortDescriptors) or
[`nsSortDescriptors`](/documentation/SwiftUI/FetchedResults/nsSortDescriptors) properties of the
[`FetchedResults`](/documentation/SwiftUI/FetchedResults) instance. Continuing the example above, to
enable the user to dynamically update the predicate, declare a
[`State`](/documentation/SwiftUI/State) property to hold a query string:

```
@State private var query = ""
```

Then add an [`onChange(of:initial:_:)`](/documentation/SwiftUI/View/onChange(of:initial:_:)) modifier to the
[`Table`](/documentation/SwiftUI/Table) that sets a new predicate any time the query changes:

```
.onChange(of: query) { _, value in
    quakes.nsPredicate = query.isEmpty
        ? nil
        : NSPredicate(format: "place CONTAINS %@", value)
}
```

To give the user control over the string, add a [`TextField`](/documentation/SwiftUI/TextField) in your
user interface that’s bound to the `query` state:

```
TextField("Filter", text: $query)
```

When the user types into the text field, the predicate updates,
the request fetches new results, and SwiftUI redraws the table.

## Topics

### Setting a predicate

[`nsPredicate`](/documentation/SwiftUI/FetchRequest/Configuration/nsPredicate)

The request’s predicate.

### Setting sort descriptors

[`sortDescriptors`](/documentation/SwiftUI/FetchRequest/Configuration/sortDescriptors)

The request’s sort descriptors, accessed as value types.

[`nsSortDescriptors`](/documentation/SwiftUI/FetchRequest/Configuration/nsSortDescriptors)

The request’s sort descriptors, accessed as reference types.

## Relationships

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Sendable`](/documentation/Swift/Sendable)

---

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)