<!--
{
  "availability" : [
    "iOS: 10.0.0 - 16.0.0",
    "iPadOS: 10.0.0 - 16.0.0",
    "macCatalyst: 13.1.0 - 16.0.0",
    "macOS: 10.12.0 - 13.0.0",
    "visionOS: 1.0.0 - 1.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "CoreSpotlight",
  "identifier" : "/documentation/CoreSpotlight/CSSearchQuery/init(queryString:attributes:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Core Spotlight"
    ],
    "preciseIdentifier" : "c:objc(cs)CSSearchQuery(im)initWithQueryString:attributes:"
  },
  "title" : "init(queryString:attributes:)"
}
-->

# init(queryString:attributes:)

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

```
convenience init(queryString: String, attributes: [String]?)
```

## Return Value

An initialized query object.

## Discussion

- queryString: A formatted string that defines the matching criteria to apply to indexed items. To learn how to construct a query string, see [Create a query string for your search](/documentation/CoreSpotlight/searching-for-information-in-your-app#Create-a-query-string-for-your-search).
  
  This parameter must not be `nil`.
  - attributes: An array of strings that represent the attributes of indexed items. Each string corresponds to a property name that your app can set for an item; for a list of possible properties, see [`CSSearchableItemAttributeSet`](/documentation/CoreSpotlight/CSSearchableItemAttributeSet). Passing `nil` for this parameter means that the query doesn’t use attributes to find matching items.

## Discussion

After you create and initialize a query object, and call [`start()`](/documentation/CoreSpotlight/CSSearchQuery/start()) to begin the query, you can’t update or reuse the query object for a new query.

---

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)