I followed these two resources and setup history tracking in SwiftData.
SwiftData History tracking: Track model changes with SwiftData history
For data deduplication: Sharing Core Data objects between iCloud users
In the sample app (CoreDataCloudKitShare), a uuid: UUID
field is used for deduplication logic. It sorts the entities by their uuid
s, reserves the first one, and marks the others as deduplicated.
Would it be a viable solution to use a createdAt: Date
field for the sort operation instead of a uuid
field, or are dates inherently problematic?
If the mentioned createdAt:
date means the creation time of a Core Data object, it is local on a device, and multiple devices may create an object at the same time; if it means the creation time on the CloudKit server side, records created in a same batch (with a same CKModifyRecordsOperation
) will have the same creation time. So overall, I think the creation time isn't as unique as a UUID.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.