<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.12.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreSpotlight",
  "identifier" : "/documentation/CoreSpotlight/CSSearchQuery/completionHandler",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Core Spotlight"
    ],
    "preciseIdentifier" : "c:objc(cs)CSSearchQuery(py)completionHandler"
  },
  "title" : "completionHandler"
}
-->

# completionHandler

The block to execute when the query finishes delivering all results.

```
var completionHandler: (((any Error)?) -> Void)? { get set }
```

## Discussion

Specify a value for this property only if you start your query with
the [`start()`](/documentation/CoreSpotlight/CSSearchQuery/start()) method. When the query finishes, the query object
executes the provided closure once to let you know the search is
complete. Use your handler to perform any related cleanup. The block
you assign to this property returns no parameters and takes the
following parameter:

- error: An error object with details about a problem that occurred, or `nil` if the query completed successfully.

If you start the query by accessing the [`results`](/documentation/CoreSpotlight/CSSearchQuery/results-swift.property)
property of [`CSSearchQuery`](/documentation/CoreSpotlight/CSSearchQuery) or the [`responses`](/documentation/CoreSpotlight/CSUserQuery/responses-swift.property) property
of [`CSUserQuery`](/documentation/CoreSpotlight/CSUserQuery), the query object doesn’t execute the block in
this property.

---

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)