<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftData",
  "identifier" : "/documentation/SwiftData/Query(filter:sort:order:transaction:sectionBy:)-3cn7t",
  "metadataVersion" : "0.1.0",
  "role" : "Macro",
  "symbol" : {
    "kind" : "Macro",
    "modules" : [
      "SwiftData",
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:011_SwiftData_A2UI5Query6filter4sort5order11transaction9sectionByy10Foundation9PredicateVyq__QPGSg_s7KeyPathCyq_xGAH9SortOrderO0aC011TransactionVSgANyq_SSGtcSLRz0aB015PersistentModelR_r0_lufm"
  },
  "title" : "Query(filter:sort:order:transaction:sectionBy:)"
}
-->

# Query(filter:sort:order:transaction:sectionBy:)

```
@attached(accessor) @attached(peer, names: prefixed(`_`)) macro Query<Value, Element>(filter: Predicate<Element>? = nil, sort keyPath: KeyPath<Element, Value>, order: SortOrder = .forward, transaction: Transaction? = nil, sectionBy sectionKeyPath: KeyPath<Element, String>) where Value : Comparable, Element : PersistentModel
```

---

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)