FetchRequest
struct · iOS 13.0+ · SDK 27.1
@MainActor @propertyWrapper @preconcurrency struct FetchRequest<Result> where Result : NSFetchRequestResultA property wrapper type that retrieves entities from a Core Data persistent store. Use a `FetchRequest` property wrapper to declare a ``FetchedResults`` property that provides a collection of Core Data managed objects to a SwiftUI view. The request infers the entity type from the `Result` placeholder type that you specify. Condition the request with an optional predicate and sort descriptors. For example, you can create a request to list all `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 their `time` property: @FetchRequest(sortDescriptors: [SortDescriptor(\.time, order: .reverse)]) private var quakes: FetchedResults<Quake> // Define Quake in your model. Alternatively, when you need more flexibility, you can initialize the request with a configured <doc://com.apple.documentation/documentation/CoreData/NSFetchRequest> instance: @FetchRequest(fetchRequest: request) private var quakes: FetchedResults<Quake> Always declare properties that have a 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 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 predicate or sort descriptors, access the request's ``FetchRequest/Configuration`` structure. To create a request that groups the fetched results according to a characteristic that they share, use ``SectionedFetchRequest`` instead.
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.
FetchRequest.wrappedValue
The containing type needs Swift generic type arguments. (no canonical witness for Result)
FetchRequest.projectedValue
The containing type needs Swift generic type arguments. (no canonical witness for Result)
FetchRequest.update()
The containing type needs Swift generic type arguments. (no canonical witness for Result)
FetchRequest.init(entity:sortDescriptors:predicate:animation:)
The containing type needs Swift generic type arguments. (no canonical witness for Result)
FetchRequest.init(fetchRequest:animation:)
The containing type needs Swift generic type arguments. (no canonical witness for Result)
FetchRequest.init(fetchRequest:transaction:)
The containing type needs Swift generic type arguments. (no canonical witness for Result)