Is there a guaranteed order for records in CKSyncEngine's handleFetchedRecordZoneChanges?

I have two recordTypes in CloudKit: Author and Book. The Book records have their parent property set to an Author, enabling hierarchical record sharing (i.e., if an Author record is shared, the participant can see all books associated with that author in their shared database).

When syncing with CKSyncEngine, I was expecting handleFetchedRecordZoneChanges to deliver all Author records before their associated Book records. However, unless I’m missing something, the order appears to be random.

This randomness forces me to handle two codepaths in my app (opposed to just one) to replicate CloudKit references in my local persistency storage:

  1. Book arrives before its Author → I store the Book but defer setting its parent reference until the corresponding Author arrives.
  2. Author arrives before its Books → I can immediately set the parent reference when each Book arrives.

Is there a way to ensure that Author records always arrive before Book records when syncing with CKSyncEngine? Or is this behavior inherently unordered and I have to implement two codepaths?

No, we don't have any documentation mentioning the order of the change set, and I won't assume that a parent record will come first when a shared hierarchy is changed.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Is there a guaranteed order for records in CKSyncEngine's handleFetchedRecordZoneChanges?
 
 
Q