Reducing overhead of CKRecord.encodeSystemFields

TL;DR: I'm syncing a local database to CloudKit and I'd like to store only the CKRecord's recordChangeTag locally, because the archived system fields are quite large. Is there any way to create a CKRecord with a given recordChangeTag?

I'm working on syncing an on-device database to CloudKit. As part of this I need to remember the CloudKit state of every database record, so I when that record changes I can create a CKRecord for it and push it to the server.

The supported way to do this is to call CKRecord.encodeSystemFields on the resulting record after the push, and save that archived data alongside the local record so it can be reconstituted into a CKRecord next time I need to push that database row.

The problem is that this archived data is pretty heavyweight, generally about 1600 bytes. That's not a lot for one record, but for 60,000 records it's 100MB of extra data to store (and read and write.)

As far as I can tell, the only really crucial part of a CKRecord to push (besides the ID and type, which I already know) is the recordChangeTag — this is what the server uses as the MVCC token to reject conflicting updates. And this tag is tiny: it appears to be a hex-encoded generation count, so it's usually 1 or 2 bytes.

I'd like to store just this tag. But I can't use it to reconstitute a CKRecord, because that property isn't settable. Is there any workaround?

did you ever come up with a solution for this? I’m not as concerned about the size, and I’m not sure which system fields would be so large, but I do need to know the best solution as it does make sense performance wise.

thank You!

Reducing overhead of CKRecord.encodeSystemFields
 
 
Q