I've posted a suggestion for a sync enabled/disabled switch on
NSPersistentCloudKitContainer through the feedback tool (FB8571301). This is the reply I got:
We do not encourage applications to implement their own sync controls. The user can control the sync state of an application using the iCloud Preferences in the Settings app.
The problem is that the iCloud preferences in the settings app are rather hidden.. And there is no way to directly link to this page from my app.
There are inherent ownership challenges with toggling between synced and unsynced data. For this reason we recommend using a separate persistent store to hold unsynced data separately from the user’s iCloud data.
This is necessarily a heavy-weight operation, the local store must be added and the cloud store removed when the user disables sync. You can customize the persistent store descriptions of a container after it is initialized. For example, you can set the store descriptions on it immediately, which will prevent the default descriptions from loading.
If the container is already loaded, you must unload all the persistent stores and then mutate the descriptions accordingly.