Reputation: 873
I have a NSDocument
-based macOS app that uses file wrappers for the document package. I have added iCloud Drive sync support. If I make changes on one Mac, the document syncs successfully to another.
However, if I edit a document on two different Macs at the same time, only one of them gets the changes; the other one loses data, since it seems file wrapper saving is atomic, so the "truth in the cloud" picks one of the documents.
What I want is to merge edited component files from each Mac — I want to be able to edit some values on one Mac, and different values on the other Mac, and have both incorporated in the document. The document is structured to support this, using separate files in the file wrappers for each value.
Is there a best practice to support this?
I already have logic to check the modification dates of the file wrappers, and only load files that have changed from when the document was previously loaded. But when the version from another Mac wins, it seems to replace those files with a more recent modification date, defeating that mechanism. I have thought about checking a date or change number encoded in each component file, but surely there's a better way?
I know that CloudKit is an alternative, and perhaps better suited for merging changes from multiple Macs, but using that would be a major change. I'd prefer to stick with NSDocument
syncing if possible.
Upvotes: 1
Views: 63