NSPersistentCloudKitContainer in duplicate processes

I have a single multiplatform application that I use NSPersistentCloudKitContainer on.

This works great, except I noticed when I open two instances of the same process (not windows) on the same computer, which share the same store, data duplication and "Metadata Inconsistency" errors start appearing.

This answer (https://stackoverflow.com/a/67243833) says this is not supported with NSPersistentCloudKitContainer.

  1. Is this indeed true?
  2. If it isn't allowed, is the only solution to disable multiple instances of the process via a lock file? I was thinking one could somehow coordinate a single "leader" process that syncs to the cloud, with the others using NSPersistentContainer, but this would be complicated when the "leader" process terminates.

Currently, it seems iPad split views are new windows, not processes -- but overall I'm still curious :0

Thank you!

  1. Is this indeed true?

Yes.

  1. If it isn't allowed, is the only solution to disable multiple instances of the process via a lock file? I was thinking one could somehow coordinate a single "leader" process that syncs to the cloud, with the others using NSPersistentContainer, but this would be complicated when the "leader" process terminates.

I'm skeptical that's a workable solution. Holding file locks across assertion boundaries will cause your app to get killed. However the system regularly suspends apps doing NSPersistentCloudKitContainer work for load balancing. There isn't a convenient process model for multiple apps coordinating on a shared networking space.

If extensions fail to meet your use case needs, you will have to elect a leader application to manage the CloudKit sync. Other applications can access the same store file without the NSPersistentCloudKitContainerOptions set, but only one process can manage sync.

NSPersistentCloudKitContainer in duplicate processes
 
 
Q