<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CloudKit",
  "identifier" : "/documentation/CloudKit/CKDatabase/fetch(withRecordIDs:desiredKeys:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "CloudKit"
    ],
    "preciseIdentifier" : "s:So10CKDatabaseC8CloudKitE5fetch13withRecordIDs11desiredKeys17completionHandlerySaySo10CKRecordIDCG_SaySSGSgys6ResultOySDyAiNySo0L0Cs5Error_pGGsAQ_pGctF"
  },
  "title" : "fetch(withRecordIDs:desiredKeys:completionHandler:)"
}
-->

# fetch(withRecordIDs:desiredKeys:completionHandler:)

Fetches the specified records and delivers them to a completion handler.

```
@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 <doc://com.apple.documentation/documentation/Swift/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 `recordIDs` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/Swift/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`](/documentation/CloudKit/CKFetchRecordsOperation).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)