在多个视图之间保持同步活动的最佳实践或设计模式是什么? [英] What is the best practice or design pattern to maintain sync activity across multiple views?
问题描述
场景:共享/同步领域.具有多个视图的iOS/Swift应用.
Scenario : Shared/Sync'd Realm. iOS/Swift App with multiple views.
为了在后台保持同步,并为多个视图提供自动(实时)更新,我应该使用哪种最佳实践设计模式?
What is the best practice design pattern I should use to in order to maintain synchronisation in the background - and - provide automatic (real time) updates to multiple views?
查看额外的任务应用程序-这很有意义,但是该应用程序实际上只有一个活动视图.如果我有多个视图怎么办?
Looking at the extra task app - this makes sense but the app really only has one active view. What if I have multiple views?
是否应该销毁Realm的数据更改通知并为每个视图重建?
Should I destroy the Realm notification of data change and rebuild for each view?
推荐答案
推荐的方法与单个视图控制器的方法相同.为每个视图控制器获取一个Results对象,并将其直接用作数据源.您可以使用Realm的通知机制来观察Results对象.当更改影响结果时,从后台线程提交任何更改,都会触发通知.结果对象已自动更新为最新状态,您只需要更新用户界面即可.
The recommended way is the same as for a single view controller. Get a Results object for each view controller and use it directly as a data source. You can observe that Results object using Realm's notification mechanism. A notification fires when changes affecting Results any changes are committed from a background thread. The Results object has been updated to the latest state automatically, what you should do is just updating the UI.
这篇关于在多个视图之间保持同步活动的最佳实践或设计模式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!