fatbobman / blogComments

1 stars 0 forks source link

如何通过 Persistent History Tracking 观察 SwiftData 的数据变化 | 肘子的Swift记事本 #205

Open fatbobman opened 10 months ago

fatbobman commented 10 months ago

https://www.fatbobman.com/posts/persistent-history-tracking-in-SwiftData/?

在数据库发生变化时 Persistent History Tracking( 持久化历史跟踪 )会向订阅者发送提醒,开发者可以借此机会对同一数据库进行的修改做出响应,包括其他应用、组件(同一个 App Group)和批处理任务。由于 SwiftData 集成了对持久化历史跟踪功能的支持,无需编写额外的代码,订阅通知、合并事务等工作都会由 SwiftData 自动完成。然而,在某些情况下,开发者可能希望自行响应持久化历史跟踪的事务,以获得更多的灵活性。本文将介绍如何在 SwiftData 中通过持久化历史跟踪观察特定数据变化的方法。

mainhanu commented 1 month ago

awesome

according to https://github.com/fatbobman/SwiftDataKit?tab=readme-ov-file, the mirror won't work on iOS 18, is there any way for SwiftData to listen to the NSPersistentStoreRemoteChange event of container.persistentStoreCoordinator?

fatbobman commented 1 month ago

@mainhanu We can use SwiftData History in iOS 18 now. https://developer.apple.com/documentation/SwiftData/Fetching-and-filtering-time-based-model-changes I will write a article about it after vacation

mainhanu commented 1 month ago

@mainhanu We can use SwiftData History in iOS 18 now. https://developer.apple.com/documentation/SwiftData/Fetching-and-filtering-time-based-model-changes I will write a article about it after vacation

thanks