<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Spotlight"
    ],
    "preciseIdentifier" : "c:objc(cs)CSSearchQuery"
  },
  "title" : "CSSearchQuery"
}
-->

# CSSearchQuery

A type you use to programmatically search the indexed app content.

```
class CSSearchQuery
```

## Overview

Use a `CSSearchQuery` object to search your app’s indexed content
using a formatted search string. To perform a search, build a predicate
string to specify the indexed attributes you want to search and the
value you want them to match. After you start the query, you receive
batches of results in the handlers you provide.

Each `CSSearchQuery` object you create performs a single search
operation and delivers the results back to your code. Build each
predicate with an attribute name, one or more values, and either a
comparison operator or the `InRange` operator. Your predicate string
takes one of the following forms:

- `attributeName operator value[modifiers]`
- `InRange(attributeName, minValue, maxValue)`

Queries search all of your app’s indexes by default. If your app
encrypts some of its indexed data, you can limit your search to one
or more of the encrypted indexes by updating the query’s [`protectionClasses`](/documentation/CoreSpotlight/CSSearchQuery/protectionClasses)
property.  The query must have access to the protected index to search it.

For more information about how to construct predicate strings for
your query, see [Searching for information in your app](/documentation/CoreSpotlight/searching-for-information-in-your-app).

## Topics

### Creating a query object

[`init(queryString:attributes:)`](/documentation/CoreSpotlight/CSSearchQuery/init(queryString:attributes:))

Initializes and returns a query object with the specified query string and item attributes.

[`init(queryString:queryContext:)`](/documentation/CoreSpotlight/CSSearchQuery/init(queryString:queryContext:))

Initializes and returns a query object with the specified query string and query context.

### Continuing an activity

[`CSSearchQueryString`](/documentation/CoreSpotlight/CSSearchQueryString)

Provides the key for the current query in the info dictionary of the user activity object.

[`CSQueryContinuationActionType`](/documentation/CoreSpotlight/CSQueryContinuationActionType)

Indicates that the activity type to continue is a search or query.

### Specifying the indexes to search

[`protectionClasses`](/documentation/CoreSpotlight/CSSearchQuery/protectionClasses)

The protection types of the indexes you want to search.

### Executing the query automatically

[`results`](/documentation/CoreSpotlight/CSSearchQuery/results-swift.property)

The results that match the current query string.

[`CSSearchQuery.Results`](/documentation/CoreSpotlight/CSSearchQuery/Results-swift.struct)

An asynchronous sequence that contains the results that match the query string.

### Executing the query with handler blocks

[`start()`](/documentation/CoreSpotlight/CSSearchQuery/start())

Starts searching the index for items that match the current query string and parameters.

[`cancel()`](/documentation/CoreSpotlight/CSSearchQuery/cancel())

Cancels the current query operation.

[`isCancelled`](/documentation/CoreSpotlight/CSSearchQuery/isCancelled)

A Boolean value that indicates whether the current query is no longer running.

[`foundItemCount`](/documentation/CoreSpotlight/CSSearchQuery/foundItemCount)

The number of matching items found for the given query string.

[`foundItemsHandler`](/documentation/CoreSpotlight/CSSearchQuery/foundItemsHandler)

The block to execute when the query delivers a new batch of matching items.

[`completionHandler`](/documentation/CoreSpotlight/CSSearchQuery/completionHandler)

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



---

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)