<!--
{
  "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(withCursor:desiredKeys:resultsLimit:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "CloudKit"
    ],
    "preciseIdentifier" : "s:So10CKDatabaseC8CloudKitE5fetch10withCursor11desiredKeys12resultsLimit17completionHandlerySo07CKQueryF0C_SaySSGSgSiys6ResultOySaySo10CKRecordIDC_ANySo0O0Cs5Error_pGtG12matchResults_AJSg05queryF0tsAS_pGctF"
  },
  "title" : "fetch(withCursor:desiredKeys:resultsLimit:completionHandler:)"
}
-->

# fetch(withCursor:desiredKeys:resultsLimit:completionHandler:)

Retrieves the next batch of records from an existing search and delivers them to a completion handler.

```
@preconcurrency func fetch(withCursor queryCursor: CKQueryOperation.Cursor, desiredKeys: [CKRecord.FieldKey]? = nil, resultsLimit: Int = CKQueryOperation.maximumResults, completionHandler: @escaping @Sendable (Result<(matchResults: [(CKRecord.ID, Result<CKRecord, any Error>)], queryCursor: CKQueryOperation.Cursor?), any Error>) -> Void)
```

## Parameters

`queryCursor`

The cursor that identifies, within the full search results, the location of the next subset of results to retrieve.

`desiredKeys`

The fields to include on each fetched record. To include all fields, specify `nil`; to fetch only system fields, specify an empty array.

`resultsLimit`

The maximum number of records to return in a single set of results.

`completionHandler`

The closure to execute with the search results.

## Discussion

The completion handler takes a single <doc://com.apple.documentation/documentation/Swift/Result> parameter that contains either a tuple, or an error if the request fails. For example, when the network is unavailable or the device doesn’t have an active iCloud account.

When present, the tuple contains the following named elements:

- `matchResults`: An array of tuples. Each tuple includes a record identifier and a <doc://com.apple.documentation/documentation/Swift/Result> that contains either the corresponding matched record, or an error that describes why CloudKit can’t provide that record. For example, if CloudKit fails to materialize an asset field, it returns an error instead of a partial record. CloudKit sorts the array according to the query’s sort descriptors.
- `queryCursor`: A cursor if the number of results exceeds `resultsLimit`; otherwise, `nil`.

If you specify `resultsLimit` and the number of matched records exceeds that value, CloudKit provides only that number of records and a *cursor* — an object that marks a specific location in the full search results. To retrieve the next subset of search results, execute this method again and pass the provided cursor from previous execution.

For information on a more configurable way to search a database, see [`CKQueryOperation`](/documentation/CloudKit/CKQueryOperation).

---

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)