I want ot observer only to remote changes ( not local) ?
I build ios swift 4 calendar events application that have notifications for each event. if i set event locally
i then set notification for this event. but i need to set the notification
for each event synced from remotes …
It’s usually better to structure your code so all GUI updates for doc changes are driven by Couchbase Lite change notifications, even changes made locally. It’s usually simpler, and reduces the chance of error.
In 1.x there was a flag on change notifications to tell which were remote, but 2.x doesn’t have it.
Doing the GUI update twice usually won’t be noticeable. If it is a problem, you can remember the doc’s sequence property after you update, and check it again in the notification handler: if it hasn’t changed, neither has the document.
(I cleaned up the formatting of your post by adding lines of 3 back-quotes around the code blocks.)
var mutableDoc = MutableDocument.init(id:id,data:data)
Not related to this thread, but that line seems wrong. That constructor is for creating a new document, but you’re using it with the same ID as the existing document. That’s a recipe for conflicts. I think what you want is a mutable copy of doc? In that case, call doc.toMutable().
Then i set un observer for db changes but get different sequences for local updates :
Each update will change the sequence. What should be happening is:
You save a change to the document (sequence changes to 999, say)
You use your own notification system to update the GUI (or other state)
Your update code draws the GUI or updates other state, and caches the documents sequence, 999
Now your CBL change listener [the code you posted] gets called; it also calls your update code
Your update code checks the document’s sequence, 999, and sees that it’s equal to its cached sequence, so it does nothing.
But then, if I have say 1000 local events I need to “cache” them all aka create separate entry in another database for each event I have to store it sequence Id. Since I cannot cache it in event model itself course I get senquence Id after the update …