---
title: "fetch(withCursor:desiredKeys:resultsLimit:completionHandler:)"
framework: cloudkit
role: symbol
role_heading: Instance Method
path: "cloudkit/ckdatabase/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.

## Declaration

```swift
@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

Discussion The completion handler takes a single 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: 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.

## See Also

### Querying Records

- [records(matching:inZoneWith:desiredKeys:resultsLimit:)](cloudkit/ckdatabase/records(matching:inzonewith:desiredkeys:resultslimit:).md)
- [records(continuingMatchFrom:desiredKeys:resultsLimit:)](cloudkit/ckdatabase/records(continuingmatchfrom:desiredkeys:resultslimit:).md)
- [fetch(withQuery:inZoneWith:desiredKeys:resultsLimit:completionHandler:)](cloudkit/ckdatabase/fetch(withquery:inzonewith:desiredkeys:resultslimit:completionhandler:).md)
- [perform(_:inZoneWith:completionHandler:)](cloudkit/ckdatabase/perform(_:inzonewith:completionhandler:).md)
- [records(matching:inZoneWith:)](cloudkit/ckdatabase/records(matching:inzonewith:).md)
