---
title: FetchDescriptor
framework: swiftdata
role: symbol
role_heading: Structure
path: swiftdata/fetchdescriptor
---

# FetchDescriptor

A type that describes the criteria, sort order, and any additional configuration to use when performing a fetch.

## Declaration

```swift
struct FetchDescriptor<T> where T : PersistentModel
```

## Mentioned in

Preserving your app’s model data across launches

## Overview

Overview Use a fetch descriptor to capture the criteria necessary to select, and optionally sort, a specific collection of models from your app’s persistent storage. A fetch descriptor retrieves only a single type of persistent model, and relies on type inference to determine the appropriate type. However, you can configure a fetch descriptor to prefetch related models of different types using the relationshipKeyPathsForPrefetching property. To fetch a collection of models, first create a fetch descriptor and specify a predicate and one or more sort descriptors. The predicate describes the attributes to filter by and the constraints to apply to those attributes. If you don’t specify a predicate, the fetch returns all models of the inferred type. You can further tweak a fetch by limiting the number of models it returns, or indicating whether the fetch evaluates any unsaved changes when it selects the models to return. After configuring the fetch descriptor, pass it to the model context’s fetch(_:) method to run the fetch. let descriptor = FetchDescriptor<Recipe>(     predicate: #Predicate { $0.isFavorite == true },     sortBy: [         .init(\.createdAt)     ] ) descriptor.fetchLimit = 10

let favoriteRecipes = try modelContext.fetch(descriptor) If you’re displaying the fetched models in a SwiftUI view, use the descriptor with the Query(_:animation:) macro instead. struct FavoriteRecipesList: View {     static var fetchDescriptor: FetchDescriptor<Recipe> {         let descriptor = FetchDescriptor<Recipe>(             predicate: #Predicate { $0.isFavorite == true },             sortBy: [                 .init(\.createdAt)             ]         )         descriptor.fetchLimit = 10         return descriptor     }

@Query(FavoriteRecipesList.fetchDescriptor) private var favoriteRecipes: [Recipe]          var body: some View {         List(favoriteRecipes) { RecipeRowView($0) }     } }

## Topics

### Creating a fetch descriptor

- [init(predicate:sortBy:)](swiftdata/fetchdescriptor/init(predicate:sortby:).md)
- [Predicate](foundation/predicate.md)
- [SortDescriptor](foundation/sortdescriptor.md)

### Constraining the fetch

- [predicate](swiftdata/fetchdescriptor/predicate.md)
- [sortBy](swiftdata/fetchdescriptor/sortby.md)
- [fetchLimit](swiftdata/fetchdescriptor/fetchlimit.md)
- [fetchOffset](swiftdata/fetchdescriptor/fetchoffset.md)
- [includePendingChanges](swiftdata/fetchdescriptor/includependingchanges.md)

### Specifying the fetched attributes

- [relationshipKeyPathsForPrefetching](swiftdata/fetchdescriptor/relationshipkeypathsforprefetching.md)
- [propertiesToFetch](swiftdata/fetchdescriptor/propertiestofetch.md)

## Relationships

### Conforms To

- [Equatable](swift/equatable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Model fetch

- [Filtering and sorting persistent data](swiftdata/filtering-and-sorting-persistent-data.md)
- [Query()](swiftdata/query().md)
- [Additional query macros](swiftdata/additionalquerymacros.md)
- [Query](swiftdata/query.md)
