fetch(withRecordIDs:desiredKeys:completionHandler:)
Fetches the specified records and delivers them to a completion handler.
Declaration
@preconcurrency func fetch(withRecordIDs recordIDs: [CKRecord.ID], desiredKeys: [CKRecord.FieldKey]? = nil, completionHandler: @escaping @Sendable (Result<[CKRecord.ID : Result<CKRecord, any Error>], any Error>) -> Void)Parameters
- recordIDs:
The identifiers of the records to fetch.
- desiredKeys:
The fields to include on each fetched record. To include all fields, specify
nil; to fetch only system fields, specify an empty array. - completionHandler:
The closure to execute with the fetch results.
Discussion
The completion handler takes the following parameters:
A Result that contains either a dictionary of fetched records, or an error if the request fails, such as when the network is unavailable or the device doesn’t have an active iCloud account. When present, the dictionary uses the identifiers you specify in
recordIDsas its keys. The value of each key is a Result that contains either the corresponding fetched record, or an error that describes why CloudKit can’t provide that record.
If you’re fetching records of different types, make sure that desiredKeys is the union of all the fields you require across each distinct record type.
For information on a more configurable way to fetch specific records, see CKFetchRecordsOperation.