How to determine model type in CKSyncEngine's nextRecordZoneChangeBatch?

I’m working on a project where I’m using CKSyncEngine to sync different types of SwiftData models, specifically User and Organization, to CloudKit. Here’s how I schedule these models to be synced:

For the User model:

let pendingSaves: [CKSyncEngine.PendingRecordZoneChange] = [.saveRecord(user.recordID)]
syncEngine.state.add(pendingRecordZoneChanges: pendingSaves)

For the Organization model:

let pendingSaves: [CKSyncEngine.PendingRecordZoneChange] = [.saveRecord(organization.recordID)]
syncEngine.state.add(pendingRecordZoneChanges: pendingSaves)

The problem arises in my CKSyncEngineDelegate's nextRecordZoneChangeBatch method where from CKRecord.ID alone I need to create the actual CKRecord that will be synced to CloudKit. This recordID alone doesn’t provide enough information to determine 1) in which local model table I need to fetch actual data to build whole CKRecord; and 2) what to put in CKRecord.recordType - whether it’s a User or an Organization.

Question: What is the best practice for passing or determining the model type (e.g., User or Organization) in nextRecordZoneChangeBatch? How should I handle this in a way that effectively differentiates between the different model types being synced?

Any advice or examples would be greatly appreciated!

Few ideas:

  1. embed the Model type in RecordID.recordName string, but this makes my recordNames longer (like resource_29af3932).
  2. fetch data by recordID in all local persistent storage, but this seems slow and there is constraint that User and Organization IDs should never be the same.
  3. introduce lookup table where from CKRecordID I can look up model type.
  4. Somehow extend CKRecordID to add model type field?

I have the exact same issue. I haven't tried it yet, but I think a lookup over persisted CKRecord encodeSystemFields should work. Since you need to persist the system fields anyway, there is no extra work to do. The only difference would be that you would have to persist the system fields before telling CKSyncEngine what to do.

How to determine model type in CKSyncEngine's nextRecordZoneChangeBatch?
 
 
Q