---
title: "Query(_:transaction:)"
framework: swiftdata
role: symbol
role_heading: Macro
path: "swiftdata/query(_:transaction:)"
---

# Query(_:transaction:)

Fetches only the subset of the attached model type that satisfy the provided fetch descriptor’s criteria.

## Declaration

```swift
@attached(accessor) @attached(peer, names: prefixed(`_`)) macro Query<Element>(_ descriptor: FetchDescriptor<Element>, transaction: Transaction? = nil) where Element : PersistentModel
```

## Parameters

- `descriptor`: The criteria, sort order, and any additional configuration to use when performing the fetch.
- `transaction`: The animation to use when updates to the fetched models trigger user interface changes.

## See Also

### Descriptor-based queries

- [Query(_:animation:)](swiftdata/query(_:animation:).md)
