1 Reply
      Latest reply on Aug 22, 2019 3:05 AM by alienspaces
      alienspaces Level 1 Level 1 (10 points)

        By the time this debug output is printed, I've loaded 2 store descriptions, into a NSPersistentCloudKitContainer, that both have the NSPersistentCloudKitContainerOptionsKey set, both with differing containerIdentifiers that exist in iCloud. Yet, attempting to initialize the schema fails saying none of my store descriptions in the coordinator are configured to use CloudKit. They definitely are configured in the MOM.

         

        Other observations: I'm beginning to think it's not advisable to have 2 configurations in one MOM that both point to different iCloud containers, because Xcode tells me that I have to add entities from one CloudKit configuration into another CloudKit configuration in order to get it to compile. Yet the one configuration contains just a single entity with no relationships at all. So that's really unexpected. Will Core Data attempt to generate CKRecords in both containers for the entities that appear in both CloudKit configurations? Perhaps it's best to use seperate MOMs (and an associated NSPersistentCloudKitContainer) for seperate CloudKit container backed configurations/stores.

         

        Any help, from anyone on this issue would be greatly appreciated.

         

        2019-08-20 22:08:00.401657+0100 TerrestrialTester[78354:2511978] Initialization options: NSPersistentCloudKitContainerSchemaInitializationOptions(rawValue: 4)

        CoreData: debug: CoreData+CloudKit: -[PFCloudKitOptionsValidator validateOptions:andStoreOptions:error:](35): Validating options: <NSCloudKitMirroringDelegateOptions: 0x6000037096c0> containerIdentifier:iCloud.com.terrestrialbytes.Terrestrial ckAssetThresholdBytes:<null> operationMemoryThresholdBytes:<null> useEncryptedStorage:NO automaticallyDownloadFileBackedFutures:NO automaticallyScheduleImportAndExportOperations:YES skipCloudKitSetup:NO preserveLegacyRecordMetadataBehavior:NO useDaemon:YES apsConnectionMachServiceName:<null> containerProvider:<PFCloudKitContainerProvider: 0x600001e18320> storeMonitorProvider:<PFCloudKitStoreMonitorProvider: 0x600001e18350> scheduler:<null> notificationListener:<null> containerOptions:<null>

        storeOptions: {

            NSAddStoreAsynchronouslyOption = 1;

            NSInferMappingModelAutomaticallyOption = 1;

            NSMigratePersistentStoresAutomaticallyOption = 1;

            NSPersistentCloudKitContainerOptionsKey = "<NSPersistentCloudKitContainerOptions: 0x600001c55be0>";

            NSPersistentHistoryTrackingKey = 1;

            NSPersistentStoreMirroringOptionsKey =     {

                NSPersistentStoreMirroringDelegateOptionKey = "<NSCloudKitMirroringDelegate: 0x600002d0d220>";

            };

        }

        CoreData: debug: CoreData+CloudKit: -[PFCloudKitOptionsValidator validateOptions:andStoreOptions:error:](35): Validating options: <NSCloudKitMirroringDelegateOptions: 0x600003703410> containerIdentifier:iCloud.com.terrestrialbytes.Appture ckAssetThresholdBytes:<null> operationMemoryThresholdBytes:<null> useEncryptedStorage:NO automaticallyDownloadFileBackedFutures:NO automaticallyScheduleImportAndExportOperations:YES skipCloudKitSetup:NO preserveLegacyRecordMetadataBehavior:NO useDaemon:YES apsConnectionMachServiceName:<null> containerProvider:<PFCloudKitContainerProvider: 0x600001e00710> storeMonitorProvider:<PFCloudKitStoreMonitorProvider: 0x600001e00730> scheduler:<null> notificationListener:<null> containerOptions:<null>

        storeOptions: {

            NSAddStoreAsynchronouslyOption = 1;

            NSInferMappingModelAutomaticallyOption = 1;

            NSMigratePersistentStoresAutomaticallyOption = 1;

            NSPersistentCloudKitContainerOptionsKey = "<NSPersistentCloudKitContainerOptions: 0x600001c55ba0>";

            NSPersistentHistoryTrackingKey = 1;

            NSPersistentStoreMirroringOptionsKey =     {

                NSPersistentStoreMirroringDelegateOptionKey = "<NSCloudKitMirroringDelegate: 0x600002d014a0>";

            };

        }

        2019-08-20 22:08:00.408956+0100 TerrestrialTester[78354:2511978] error: A Core Data error occurred.

        2019-08-20 22:08:00.409321+0100 TerrestrialTester[78354:2511978] userInfo: {

            NSLocalizedFailureReason = "Couldn't initialize CloudKit schema because no stores in the coordinator are configured to use CloudKit: (\n)";

        }

        • Re: CD4CK wont initialize CloudKit schema
          alienspaces Level 1 Level 1 (10 points)

          OK so it turns out that setting my store descriptions to be added asyncrounsly was the issue. I was hoping it would parallelize the adding of multiple stores within a larger synchronous operation, but the implications are wider. The entire loadPersistentStores method becomes asynchronous, in my experience.It did create two scemas. One in each iCloud container. The problem is that schema designer, isn't capable of supporting multiple iCloud container configurations. And that makes sense because there is nowhere in the schema designer to set the iCloud container IDs. So it will simply complain that CloudKit backed configurations need to have the same entities in them. You'll see a lot of errors like this...xcdatamodel: error: CloudKit Integration: Container.children destination entity ContainerRelation is missing from these configurations: Appture, CloudDataKit.

           

          Both configurations Appture, and CloudDataKit have CloudKit enabled for each, and each only has a single entity in it, with zero relations.

           

          So it's probably best to have separate MOMs for each iCloud container, and use separate instances of NSPersistentCloudKitContainer to manage them in your code.

           

          If i’m wrong with regard to any of this, it would be great to get steered in the correct direction. Because there is some ambiguity in this design, as you can set multiple store descriptions on a NSPersistentCloudKitContainer, with different NSPersistentCloudKitContainerOptions, pointing to different iCloud containers, but it seems like that’s more flexible than the schema designer  in Xcode will allow.