ModelContext.NotificationKey.historyTokens
A history token representing the persistent store state after the save.
Declaration
case historyTokensDiscussion
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:
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 }
)
}