<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "swift: 5.9.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftData",
  "identifier" : "/documentation/SwiftData/HistoryDescriptor/init(predicate:sortBy:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftData"
    ],
    "preciseIdentifier" : "s:9SwiftData17HistoryDescriptorV9predicate6sortByACyxG10Foundation9PredicateVyx_QPGSg_SayAG04SortD0VyxGGtcfc"
  },
  "title" : "init(predicate:sortBy:)"
}
-->

# init(predicate:sortBy:)

Initializes a new history descriptor with the provided predicate and sort descriptor.

```
init(predicate: Predicate<TransactionType>? = nil, sortBy: [SortDescriptor<TransactionType>] = [])
```

## Parameters

`predicate`

The logical condition that determines whether the history includes a specific model in its results. The default value is `nil`.

`sortBy`

The array of sort descriptors that tell the history how to order its results. The default value is an empty array.

## Discussion

If you don’t specify a predicate, any fetch using this descriptor will return
all models of the associated type. If you expect the number of fetched transactions
to be high, use [`fetchLimit`](/documentation/SwiftData/HistoryDescriptor/fetchLimit) to limit the number of transactions returned.

---

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)