init(fetchRequest : NSFetchRequest <Result>, sectionIdentifier : KeyPath <Result, SectionIdentifier >, transaction: Transaction)
SectionIdentifier
conforms to Hashable
and Result
conforms to NSFetchRequestResult
.Availability 有効性
Technology
init(fetchRequest: NSFetchRequest
<Result>, sectionIdentifier: KeyPath
<Result, SectionIdentifier >, animation: Animation
? = nil)
SectionIdentifier
conforms to Hashable
and Result
conforms to NSFetchRequestResult
.fetchRequest
An NSFetch
instance that describes the search criteria for retrieving data from the persistent store.
sectionIdentifier
A key path that SwiftUI applies to the Result
type to get an object’s section identifier.
animation
The animation to use for user interface changes that result from changes to the fetched results.
Use this initializer when you want to configure a fetch request with more than a predicate and sort descriptors. For example, you can vend a request from a Quake
managed object that the Loading and Displaying a Large Data Feed sample code project defines to store earthquake data. Limit the number of results to 1000
by setting a fetch
for the request:
extension Quake {
var request: NSFetchRequest<Quake> {
let request = NSFetchRequest<Quake>(entityName: "Quake")
request.sortDescriptors = [
NSSortDescriptor(
keyPath: \Quake.time,
ascending: true)]
request.fetchLimit = 1000
return request
}
}
Use the request to define a Sectioned
property:
<String, Quake>(
fetchRequest: Quake.request,
sectionIdentifier: \.day)
private var quakes: FetchedResults<String, Quake>
If you only need to configure the request’s section identifier, predicate, and sort descriptors, use init(section
instead. If you need to specify a Transaction
rather than an optional Animation
, use init(fetch
.
init(fetchRequest : NSFetchRequest <Result>, sectionIdentifier : KeyPath <Result, SectionIdentifier >, transaction: Transaction)
SectionIdentifier
conforms to Hashable
and Result
conforms to NSFetchRequestResult
.