I am attempting to migrate a cloudkit module that calls on manual cloudkit methods for fetching record zone changes, modifying records, etc to one that utilizes CKSyncEngine. I've got a basic implementation working with just a create method for one of my data models, however it seems like the sync engine keeps calling sync events on the same pending changes.
Here is my current flow:
- The user will hit some button that lets them fill out a form to create a data model.
- The user saves the form. This triggers a method that takes the resulting data model and queues it to the sync engine's state (
engine.state.add(pendingRecordZoneChanges: pendingChanges)
- I have my delegate method
nextRecordZoneChangeBatch(_ context:...)
implemented where it fetches the corresponding data model using the record ID and returns a batch containing the corresponding populated record from the data model. - I have the
handleEvent(_ event:...)
delegate method implemented where I handle both.fetchRecordZoneChanges
and.sentRecordZoneChanges
. I have set up.sentRecordZoneChanges
to merge the server record into my local record (and persisted locally) so that the record change tags are the same.
After this last portion, it seems that the sync engine continues to keep pushing syncs/updates and I end up with numerous handleEvent(_ event:)
calls that keep returning savedRecords
(and occasionally failedRecordSaves
).
Am I missing some step to remove the record from the changes after the sync engine recognizes that I have properly saved the record to the server?