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

# sortBy

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

## Declaration

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

## Discussion

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:).

## See Also

### Constraining the fetch

- [predicate](swiftdata/fetchdescriptor/predicate.md)
- [fetchLimit](swiftdata/fetchdescriptor/fetchlimit.md)
- [fetchOffset](swiftdata/fetchdescriptor/fetchoffset.md)
- [includePendingChanges](swiftdata/fetchdescriptor/includependingchanges.md)
