Customize behavior of NSPersistentCloudKitContainer

I'm working on a SwiftUI app generating data using a standard CoreData data model and sync it with iCloud using NSPersistentCloudKitContainer. In this data model one parent is referencing on many children (e.g. > 2000 of children A and B). Each child A is also referencing onto one child B and vice versa:

Parent ----> Child A; Parent ----> Child B; Child A <---> Child B

The problem I am facing is, depending on the last time an CloudKit sync has been performed, the sync process takes hours to complete (where in the mean time the app might be sent to the background by the system or by the user and the sync is stopped).

  • Is there a way to efficiently sync these larger datasets?

Additionally I would like to pause the iCloud sync for specific occasions e.g. when performing continuous tasks using "Background Modes" and the app would be killed due to CPU pressure of iCloud sync.

  • Is there a way to customize the syncing behavior of NSPersistentCloudKitContainer like e.g. CKOperation or by scheduled execution of iCloud sync via "Background Tasks" or "Background Fetch"?

Thank you for you help.

Customize behavior of NSPersistentCloudKitContainer
 
 
Q