<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "swift: 5.9.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftData",
  "identifier" : "/documentation/SwiftData/FetchDescriptor/sortBy",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "SwiftData"
    ],
    "preciseIdentifier" : "s:9SwiftData15FetchDescriptorV6sortBySay10Foundation04SortD0VyxGGvp"
  },
  "title" : "sortBy"
}
-->

# sortBy

The sort descriptors that tell the fetch how to order its results.

```
var sortBy: [SortDescriptor<T>]
```

## Discussion

Use this property to specify how to arrange the collection of models that a
fetch returns. For example, if your app defines a `Person` model, you may want
to sort by the `surname` attribute, then by the `firstName` attribute. The
fetch applies the sort descriptors in the same order as they appear in the
array.

The default value is the array you specify when calling [`init(predicate:sortBy:)`](/documentation/SwiftData/FetchDescriptor/init(predicate:sortBy:)).

---

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)