wrappedValue
The fetched results of the fetch request.
Declaration
@MainActor @preconcurrency var wrappedValue: FetchedResults<Result> { get }Discussion
SwiftUI returns the value associated with this property when you use FetchRequest as a property wrapper, and then access the wrapped property by name. For example, consider the following quakes property declaration that fetches a Quake type that the Loading and Displaying a Large Data Feed sample code project defines:
@FetchRequest(fetchRequest: request)
private var quakes: FetchedResults<Quake>You access the request’s wrappedValue, which contains a FetchedResults instance, by referring to the quakes property by name:
Text("Found \(quakes.count) earthquakes")If you need to separate the request and the result entities, you can declare quakes in two steps by using the request’s wrappedValue to obtain the results:
var fetchRequest = FetchRequest<Quake>(fetchRequest: request)
var quakes: FetchedResults<Quake> { fetchRequest.wrappedValue }The wrappedValue property returns an empty array when there are no fetched results — for example, because no entities satisfy the predicate, or because the data store is empty.