我仍然无法理解,问题是什么问题 nspersistentestytorytransaction
正在尝试在coredatacloudkitdemo wwdc 2019中使用coundkit的核心数据
https://github.com/software123inc/CoreDataCloudKitDemo/blob/master/CoreDataCloudKitDemo/DataProvider/CoreDataStack.swift#L161
我想看看,如果未执行 processpersistentery
,将会发生什么问题。
通过使 processpersistentery
空,我尝试进行以下测试。
- 同时在同一台计算机中运行2个模拟器。
- 将项目添加到模拟器A中。
- 由于模拟器B无法接收推送通知,因此我按SimulatorB的主按钮B。
- 在模拟器B中,我点击了应用程序图标再次启动该应用程序。
- 在模拟器B中,我可以观察到
ControllerDidchangeContent
。我的猜测是,由于CloudKit背景任务无缝更新后支持的SQLite,因此将通知SQLite DB Change nsfetchedResultController ,随后更新UI。检查
- In simulator B, due to
controllerDidChangeContent
is being triggered correctly, I can observe the UI change perform by NSFetchResultController
without issue.
因此,我尚不清楚,关于哪个问题 processpersistestentory
正在尝试在演示代码中求解。我可以知道我可以执行什么样的测试案例,以了解 processpersistentestory
解决的问题?
Based on "Integrate Store Changes Relevant to the Current View"
https://developer.apple. com/documentation/coredata/riveror_a_core_data_store_store_with_cloudkit/syncing_a_core_core_data_store_store_store_with_cloudkit
当地商店时,您的应用程序会收到远程更改通知
来自CloudKit的更新。但是,没有必要在
对每个通知的响应,因为某些更改可能不是
与当前视图有关。
分析持久历史记录以确定这些更改是否是
与当前视图有关,然后在用户中消耗它们之前
界面。检查每个交易的详细信息,例如实体
名称,更新的属性以及更改的类型,以决定
是否行动。
有关持续历史跟踪的更多信息,请参阅消费
相关商店更改。
这部分变得令人困惑。我们的 nsfetchedResultController
由于SQLITE引起的相关实体变更事件,随后能够正确更新UI。如果是这样,为什么我们仍然需要持久的历史?
I still fail to understand, what is the problem NSPersistentHistoryTransaction
is trying to solve, in the CoreDataCloudKitDemo WWDC 2019 "Using Core Data with CloudKit"
https://github.com/software123inc/CoreDataCloudKitDemo/blob/master/CoreDataCloudKitDemo/DataProvider/CoreDataStack.swift#L161
I want to see, what problem will occur, if processPersistentHistory
is not executed.
By making the processPersistentHistory
empty, I try to do the following testing.
- Run 2 simulators simultaneously in the same machine.
- Add an item to simulator A.
- Since, there is no way for simulator B to receive push notification, I press the home button for simulator B.
- In simulator B, I tap on the app icon to launch the app again.
- In simulator B, I can observe
controllerDidChangeContent
is being called. My guess is that, because the backed SQLite is seamlessly updated by CloudKit background task, NSFetchedResultController
will be notified the SQLite DB change, and subsequently update the UI. Check the "Download CloudKit Changes into Core Data" of https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/syncing_a_core_data_store_with_cloudkit
- In simulator B, due to
controllerDidChangeContent
is being triggered correctly, I can observe the UI change perform by NSFetchResultController
without issue.
Hence, I am not clear, on what problem processPersistentHistory
is trying to solve in the demo code. May I know what kind of test case I can perform, to understand the problem solved by processPersistentHistory
?
Based on "Integrate Store Changes Relevant to the Current View"
https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/syncing_a_core_data_store_with_cloudkit
Your app receives remote change notifications when the local store
updates from CloudKit. However, it’s unnecessary to update your UI in
response to every notification, because some changes may not be
relevant to the current view.
Analyze the persistent history to determine whether the changes are
relevant to the current view before consuming them in the user
interface. Inspect the details of each transaction, such as the entity
name, its updated properties, and the type of change, to decide
whether to act.
For more information about persistent history tracking, see Consuming
Relevant Store Changes.
This part is getting confusing. Our NSFetchedResultController
is receiving relevant entity change event due to SQLite, and subsequently able to update the UI correct. If that is so, why do we still need persistent history?
发布评论
评论(1)
您是对的,NSfetchedResultScontroller能够接收更新并触发UI的更新。
因此,问题就变成了您从Coredata显示数据的UI,并且不使用NsfetchedResultScontroller?
对于我的,它是一种编辑项目的表单,我将其从NSfetchedResultScontroller中传递给了它作为形式成员变量。此表格无法接收此类更新。
查看coredatacloudkitdemo,还有一个详细信息,它正在让用户编辑一个帖子,并且每当从另一个设备中删除此帖子时,具有持久的历史记录跟踪(和查询生成)允许其“陷阱”此更改并显示POP,并显示一个POP关闭编辑表格之前。
You are right that NSFetchedResultsController are able to receive updates, and trigger updates to the UI.
So the question becomes, in which UI of your app that you display data from CoreData, and do not use NSFetchedResultsController?
For mine, it is a form editing an item, which I just pass one of item from the NSFetchedResultsController into it as a form member variable. This Form is not able to receive such updates.
Looking at the CoreDataCloudKitDemo, there's also this DetailView, that is letting user edit a single post, and whenever this post is deleted from another device, having persistent history tracking (and query generation) allow it to "trap" this change and show a pop up before closing the edit form.