FetchedResults
struct · iOS 13.0+ · SDK 27.1
@MainActor @preconcurrency struct FetchedResults<Result> where Result : NSFetchRequestResultA collection of results retrieved from a Core Data store. Use a `FetchedResults` instance to show or edit Core Data managed objects in your app's user interface. You request a particular set of results by specifying a `Result` type as the entity type, and annotating the fetched results property declaration with a ``FetchRequest`` property wrapper. 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> The results instance conforms to <doc://com.apple.documentation/documentation/Swift/RandomAccessCollection>, so you access it like any other collection. For example, you can create a ``List`` that iterates over all the results: List(quakes) { quake in NavigationLink(destination: QuakeDetail(quake: quake)) { QuakeRow(quake: quake) } } When you need to dynamically change the request's predicate or sort descriptors, set the result instance's ``nsPredicate`` and ``sortDescriptors`` or ``nsSortDescriptors`` properties, respectively. 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 container that you define as part of your model: ContentView() .environment( \.managedObjectContext, QuakesProvider.shared.container.viewContext)
Members (0)
This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.
Skipped declarations
5 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
FetchedResults.nsSortDescriptors
The containing type needs Swift generic type arguments. (no canonical witness for Result)
FetchedResults.nsPredicate
The containing type needs Swift generic type arguments. (no canonical witness for Result)
FetchedResults.startIndex
The containing type needs Swift generic type arguments. (no canonical witness for Result)
FetchedResults.endIndex
The containing type needs Swift generic type arguments. (no canonical witness for Result)
FetchedResults.subscript(_:)
This declaration needs Swift generic type arguments. (no canonical witness for Result)