<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "swift: 5.9.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftData",
  "identifier" : "/documentation/SwiftData/ModelContext/NotificationKey/historyTokens",
  "metadataVersion" : "0.1.0",
  "role" : "Case",
  "symbol" : {
    "kind" : "Case",
    "modules" : [
      "SwiftData"
    ],
    "preciseIdentifier" : "s:9SwiftData12ModelContextC15NotificationKeyO13historyTokensyA2EmF"
  },
  "title" : "ModelContext.NotificationKey.historyTokens"
}
-->

# ModelContext.NotificationKey.historyTokens

A history token representing the persistent store state after the save.

```
case historyTokens
```

## Discussion

This key is available in `ModelContext.didSave` notifications (it is not present
in `willSave` notifications). The value is an instance conforming to `HistoryToken`.

Use this token with `HistoryDescriptor` to fetch only changes that occurred
after this save operation:

```swift
NotificationCenter.default.addObserver(
    forName: ModelContext.didSave,
    object: nil,
    queue: nil
) { notification in
    guard let token = notification.userInfo?[ModelContext.NotificationKey.historyToken] as? DefaultHistoryToken else {
        return
    }

    // Use token to fetch changes since this save
    let descriptor = HistoryDescriptor<DefaultHistoryTransaction>(
        predicate: #Predicate { $0.token > token }
    )
}
```

---

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)