---
title: sortBy
framework: swiftdata
role: symbol
role_heading: Instance Property
path: swiftdata/resultsobserver/sortby
---

# sortBy

The sort descriptors used to order the results.

## Declaration

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

## Discussion

Discussion Setting this property updates the underlying 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.

## See Also

### Accessing observer properties

- [fetchDescriptor](swiftdata/resultsobserver/fetchdescriptor.md)
- [filterBy](swiftdata/resultsobserver/filterby.md)
- [modelContext](swiftdata/resultsobserver/modelcontext.md)
- [sectionBy](swiftdata/resultsobserver/sectionby.md)
- [sections](swiftdata/resultsobserver/sections.md)
- [ResultsSectionCollection](swiftdata/resultssectioncollection.md)
