<!--
{
  "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/ResultsObserver/sortBy",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "SwiftData"
    ],
    "preciseIdentifier" : "s:9SwiftData15ResultsObserverC6sortBySay10Foundation14SortDescriptorVyxGGvp"
  },
  "title" : "sortBy"
}
-->

# sortBy

The sort descriptors used to order the results.

```
final var sortBy: [SortDescriptor<Element>] { get set }
```

## Discussion

Setting this property updates the underlying [`fetchDescriptor`](/documentation/SwiftData/ResultsObserver/fetchDescriptor)‘s sort descriptors and
immediately refetches on the calling actor. When sectioning is active, the section’s sort
descriptor is automatically re-prepended if not already the first descriptor. A
`SortDescriptor` by `persistentModelID` is appended automatically if not already present
to ensure stable ordering for difference computation.

---

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)