How to temporarily suppress notifications


#1

My iOS map app needs to update in real time when a History object changes.
However, there is one case where I modify a lot of History objects that won’t affect the map, so I don’t want the map repeatedly updating during this case.
I saw an old doc with realm.writeCommit(withoutNotifying: someToken].
However, I can’t find anything else on that.
I am using the form of realm.write { /* closure */ } and would like to suppress notifications for History objects just during this particular transaction.
I could turn off the map notification block, but I don’t want the overhead of sending notifications to nobody.
Is this possible with RealmSwift?
Thanks.


#2

Hi, it is in the current docs: https://realm.io/docs/swift/latest/#interface-driven-writes
Try it out, it works.


#3

Thanks for your response claverack. Unfortunately, the code that does the History writes has no way of knowing what the map’s notification token is, unless I build a lot of ugly infrastructure.
If I could pass in withoutNotifying: ANYBODY, that would be perfect.
I don’t suppose there’s any way to turn off notifications at the realm level. realm.notificationsEnabled = false
Thanks.


#4

Oh I understand. I would set a breakpoint in one of your observe callbacks and see what happens in the Realm source code before the notifications are sent. Then you could add your own flag that prevents the callbacks to be executed.


#5

Ah, good idea. thanks!