<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftData",
  "identifier" : "/documentation/SwiftData/HistoryObserver/init(historyTokens:observedModels:authors:modelContainer:isolation:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftData"
    ],
    "preciseIdentifier" : "s:9SwiftData15HistoryObserverC13historyTokens14observedModels7authors14modelContainer9isolationACSDySSAA0C5Token_pGSg_SayAA15PersistentModel_pXpGShySSGAA0oK0CScA_pSgYitKcfc"
  },
  "title" : "init(historyTokens:observedModels:authors:modelContainer:isolation:)"
}
-->

# init(historyTokens:observedModels:authors:modelContainer:isolation:)

Creates a history observer that reports changes through its observable
[`eventCounter`](/documentation/SwiftData/HistoryObserver/eventCounter) property.

```
convenience init(historyTokens: [String : any HistoryToken]? = nil, observedModels: [any PersistentModel.Type] = [], authors: Set<String> = [], modelContainer: ModelContainer, isolation: isolated (any Actor)? = #isolation) throws
```

## Parameters

`historyTokens`

The initial history tokens keyed by store identifier.
When `nil`, the observer captures the current position for each
store immediately, so that only transactions from this point
forward are reported.

`observedModels`

The model types to filter for. When empty (the
default), the observer responds to changes for any model.

`authors`

The transaction authors to filter for. When empty (the
default), the observer responds to changes from any author.

`modelContainer`

The model container to observe.

## Discussion

Use this initializer when you want to observe history changes via
SwiftUI’s observation system or by reading [`eventCounter`](/documentation/SwiftData/HistoryObserver/eventCounter) directly.

> Throws: An error if the observer fails to fetch the initial history tokens.

---

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)