<!--
{
  "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/init(filter:sort:order:animation:sectionBy:)-4peqq",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftData",
      "SwiftUI",
      "_SwiftData_SwiftUI"
    ],
    "preciseIdentifier" : "s:011_SwiftData_A2UI5QueryV6filter4sort5order9animation9sectionByACyx0aB016SectionedResultsVyxSSGG10Foundation9PredicateVyx_QPGSg_s7KeyPathCyxqd__GAN9SortOrderO0aC09AnimationVATyxSSSgGtcALRs_SLRd__lufc"
  },
  "title" : "init(filter:sort:order:animation:sectionBy:)"
}
-->

# init(filter:sort:order:animation:sectionBy:)

Creates a sectioned query sorted by a key path, grouped by a required optional-String key path. `nil` values share the empty-string section.

```
@MainActor @preconcurrency init<Value>(filter: Predicate<Element>? = nil, sort keyPath: KeyPath<Element, Value>, order: SortOrder = .forward, animation: Animation, sectionBy sectionKeyPath: KeyPath<Element, String?>) where Result == SectionedResults<Element, String>, Value : Comparable
```

---

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)