---
title: "init(queryString:attributes:)"
framework: corespotlight
role: symbol
role_heading: Initializer
path: "corespotlight/cssearchquery/init(querystring:attributes:)"
---

# init(queryString:attributes:)

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

## Declaration

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

## Return Value

Return Value An initialized query object.

## Discussion

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. 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. 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() to begin the query, you can’t update or reuse the query object for a new query.

## See Also

### Creating a query object

- [init(queryString:queryContext:)](corespotlight/cssearchquery/init(querystring:querycontext:).md)
