Is Core Data hosted in CloudKit working in Xcode 13?

Hi, I'm pretty new to SwiftUI. I created a project in Xcode 12 using CoreData and Hosted in CloudKit. This auto-generated some code which (mostly) works (the template did not display the add or edit buttons in iOS / iPadOS since it lacks a navigation view [I know it is just an example view to get started, but I was surprised by this] and is also missing a mergePolicy and automaticallyMergesChangesFromParent to see results in a timely fashion [well around 15 seconds or so])... anyway... I got that figured out and it works well in the iOS / iPadOS simulators in Xcode 12 plus when run on my iPod touch and iPad Pro with the same version OS.

I just tried opening the project in Xcode 13 Beta and the iOS / iPadOS simulators to look around and right away, the syncing with iCloud isn't working. Is there something new required? Xcode 13 isn't showing any warnings or cautions with the code. Is this just a bug in the current beta that needs to be fixed? I'm also curious, is there a way to use the new concurrency in SwiftUI with the syncing between Core Data and iCloud if I wanted to check if something already exists in iCloud after it is done syncing before automatically generating some new data?

I'm attaching the errors reported in Xcode 13 Beta as the simulator ran the project:

CoreData: debug: CoreData+CloudKit: -[PFCloudKitOptionsValidator validateOptions:andStoreOptions:error:](36): Validating options: <NSCloudKitMirroringDelegateOptions: 0x600002c21080> containerIdentifier:iCloud.com.yenco.iKeeper databaseScope:Private ckAssetThresholdBytes:<null> operationMemoryThresholdBytes:<null> useEncryptedStorage:NO useDeviceToDeviceEncryption:NO automaticallyDownloadFileBackedFutures:NO automaticallyScheduleImportAndExportOperations:YES skipCloudKitSetup:NO preserveLegacyRecordMetadataBehavior:NO useDaemon:YES apsConnectionMachServiceName:<null> containerProvider:<PFCloudKitContainerProvider: 0x6000000383d0> storeMonitorProvider:<PFCloudKitStoreMonitorProvider: 0x600000038420> metricsClient:<PFCloudKitMetricsClient: 0x600000038460> metadataPurger:<PFCloudKitMetadataPurger: 0x600000038470> scheduler:<null> notificationListener:<null> containerOptions:<null> defaultOperationConfiguration:<null> progressProvider:<NSPersistentCloudKitContainer: 0x6000017723c0>
storeOptions: {
    NSInferMappingModelAutomaticallyOption = 1;
    NSMigratePersistentStoresAutomaticallyOption = 1;
    NSPersistentCloudKitContainerOptionsKey = "<NSPersistentCloudKitContainerOptions: 0x600000c6b180>";
    NSPersistentHistoryTrackingKey = 1;
    NSPersistentStoreMirroringOptionsKey =     {
        NSPersistentStoreMirroringDelegateOptionKey = "<NSCloudKitMirroringDelegate: 0x600003736ac0>";
    };
}
CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate observeChangesForStore:inPersistentStoreCoordinator:](405): <NSCloudKitMirroringDelegate: 0x600003736ac0>: Observing store: <NSSQLCore: 0x7f98ebd08da0> (URL: file:///Users/mikeyenco/Library/Developer/CoreSimulator/Devices/FAADBCAB-8F4B-4441-84D9-D8E090797CBB/data/Containers/Data/Application/2367E1AA-CDE1-4602-8D75-716BB7715DF9/Library/Application%20Support/iKeeper.sqlite)
CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _setUpCloudKitIntegration](514): <NSCloudKitMirroringDelegate: 0x600003736ac0>: Successfully enqueued setup request.
CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate checkAndExecuteNextRequest](2658): <NSCloudKitMirroringDelegate: 0x600003736ac0>: Checking for pending requests.
CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate checkAndExecuteNextRequest]_block_invoke(2671): <NSCloudKitMirroringDelegate: 0x600003736ac0>: Executing: <NSCloudKitMirroringDelegateSetupRequest: 0x600000c079f0> 94F73B08-F9A9-420D-9373-3F2E2986C129
CoreData: debug: CoreData+CloudKit: -[PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:](445): Skipping migration for 'ANSCKDATABASEMETADATA' because it already has a column named 'ZLASTFETCHDATE'
CoreData: debug: CoreData+CloudKit: -[PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:](500): Skipping migration for 'ANSCKMETADATAENTRY' because it already has a column named 'ZDATEVALUE'
CoreData: debug: CoreData+CloudKit: -[PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:](445): Skipping migration for 'ANSCKRECORDZONEMETADATA' because it already has a column named 'ZLASTFETCHDATE'
CoreData: debug: CoreData+CloudKit: -[PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:](461): Skipping migration for 'ANSCKRECORDZONEMETADATA' because it already has a column named 'ZSUPPORTSFETCHCHANGES'
CoreData: debug: CoreData+CloudKit: -[PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:](461): Skipping migration for 'ANSCKRECORDZONEMETADATA' because it already has a column named 'ZSUPPORTSATOMICCHANGES'
CoreData: debug: CoreData+CloudKit: -[PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:](461): Skipping migration for 'ANSCKRECORDZONEMETADATA' because it already has a column named 'ZSUPPORTSRECORDSHARING'
CoreData: debug: CoreData+CloudKit: -[PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:](461): Skipping migration for 'ANSCKRECORDZONEMETADATA' because it already has a column named 'ZSUPPORTSZONESHARING'
CoreData: debug: CoreData+CloudKit: -[PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:](476): Skipping migration for 'ANSCKRECORDZONEMETADATA' because it already has a column named 'ZNEEDSIMPORT'
CoreData: debug: CoreData+CloudKit: -[PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:](476): Skipping migration for 'ANSCKRECORDZONEMETADATA' because it already has a column named 'ZNEEDSRECOVERYFROMZONEDELETE'
CoreData: debug: CoreData+CloudKit: -[PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:](476): Skipping migration for 'ANSCKRECORDZONEMETADATA' because it already has a column named 'ZNEEDSRECOVERYFROMUSERPURGE'
CoreData: debug: CoreData+CloudKit: -[PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:](476): Skipping migration for 'ANSCKRECORDZONEMETADATA' because it already has a column named 'ZENCODEDSHAREDATA'
CoreData: debug: CoreData+CloudKit: -[PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:](476): Skipping migration for 'ANSCKRECORDZONEMETADATA' because it already has a column named 'ZNEEDSSHAREUPDATE'
CoreData: CloudKit: CoreData+CloudKit: -[PFCloudKitSetupAssistant _checkUserIdentity:]_block_invoke(1098): <PFCloudKitSetupAssistant: 0x600002631f80>: CKIdentity record matches store: <CKRecordID: 0x60000021bee0; recordName=_33778a63510c168614ad62b2b67f7f90, zoneID=_defaultZone:__defaultOwner__>
2021-06-12 12:50:42.873393-0400 iKeeper[1447:39986] [error] error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _performSetupRequest:]_block_invoke(955): <NSCloudKitMirroringDelegate: 0x600003736ac0>: Failed to set up CloudKit integration for store: <NSSQLCore: 0x7f98ebd08da0> (URL: file:///Users/mikeyenco/Library/Developer/CoreSimulator/Devices/FAADBCAB-8F4B-4441-84D9-D8E090797CBB/data/Containers/Data/Application/2367E1AA-CDE1-4602-8D75-716BB7715DF9/Library/Application%20Support/iKeeper.sqlite)
<CKError 0x600000c4b1b0: "Partial Failure" (2/1011); "Failed to modify some record zones"; partial errors: {
	com.apple.coredata.cloudkit.zone:__defaultOwner__ = <CKError 0x600000c4bb10: "Internal Error" (1/5000); "Failed to sync user keys">
}>
CoreData: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _performSetupRequest:]_block_invoke(955): <NSCloudKitMirroringDelegate: 0x600003736ac0>: Failed to set up CloudKit integration for store: <NSSQLCore: 0x7f98ebd08da0> (URL: file:///Users/mikeyenco/Library/Developer/CoreSimulator/Devices/FAADBCAB-8F4B-4441-84D9-D8E090797CBB/data/Containers/Data/Application/2367E1AA-CDE1-4602-8D75-716BB7715DF9/Library/Application%20Support/iKeeper.sqlite)
<CKError 0x600000c4b1b0: "Partial Failure" (2/1011); "Failed to modify some record zones"; partial errors: {
	com.apple.coredata.cloudkit.zone:__defaultOwner__ = <CKError 0x600000c4bb10: "Internal Error" (1/5000); "Failed to sync user keys">
}>
2021-06-12 12:50:42.873566-0400 iKeeper[1447:39986] [error] error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate recoverFromError:](1923): <NSCloudKitMirroringDelegate: 0x600003736ac0> - Attempting recovery from error: <CKError 0x600000c4b1b0: "Partial Failure" (2/1011); "Failed to modify some record zones"; partial errors: {
	com.apple.coredata.cloudkit.zone:__defaultOwner__ = <CKError 0x600000c4bb10: "Internal Error" (1/5000); "Failed to sync user keys">
}>
CoreData: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate recoverFromError:](1923): <NSCloudKitMirroringDelegate: 0x600003736ac0> - Attempting recovery from error: <CKError 0x600000c4b1b0: "Partial Failure" (2/1011); "Failed to modify some record zones"; partial errors: {
	com.apple.coredata.cloudkit.zone:__defaultOwner__ = <CKError 0x600000c4bb10: "Internal Error" (1/5000); "Failed to sync user keys">
}>
2021-06-12 12:50:42.873840-0400 iKeeper[1447:39986] [error] error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _recoverFromPartialError:forStore:inMonitor:]_block_invoke(2182): <NSCloudKitMirroringDelegate: 0x600003736ac0>: Found unknown error as part of a partial failure: <CKError 0x600000c4bb10: "Internal Error" (1/5000); "Failed to sync user keys">
CoreData: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _recoverFromPartialError:forStore:inMonitor:]_block_invoke(2182): <NSCloudKitMirroringDelegate: 0x600003736ac0>: Found unknown error as part of a partial failure: <CKError 0x600000c4bb10: "Internal Error" (1/5000); "Failed to sync user keys">
CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _finishedRequest:withResult:](2689): Finished request: <NSCloudKitMirroringDelegateSetupRequest: 0x600000c079f0> 94F73B08-F9A9-420D-9373-3F2E2986C129 with result: <NSCloudKitMirroringResult: 0x600000240000> success: 0 madeChanges: 0 error: <CKError 0x600000c4b1b0: "Partial Failure" (2/1011); "Failed to modify some record zones"; partial errors: {
	com.apple.coredata.cloudkit.zone:__defaultOwner__ = <CKError 0x600000c4bb10: "Internal Error" (1/5000); "Failed to sync user keys">
}>
CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate checkAndExecuteNextRequest](2658): <NSCloudKitMirroringDelegate: 0x600003736ac0>: Checking for pending requests.
CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate checkAndExecuteNextRequest]_block_invoke(2674): <NSCloudKitMirroringDelegate: 0x600003736ac0>: No more requests to execute.
Answered by mwcs01 in 682098022

I was able to get it to work today after updating to beta 3 versions. I did have to do a erase all contents and settings on the simulator and once that was done data from CloudKit came into my app.

Exact same issue here.

Looking at the logs, it appears the issue might be related to <CKError 0x60000015a400: "Internal Error" (1/5000); "Failed to sync user keys"> as almost every line with an error has that message.

Edit: I meant to comment instead of answer.

I talked with Apple about this during a lab session at WWDC21. They had me create a feedback ticket.

Here is the Feedback: FB9156589

Im having exactly the same problem. So far no resolution. Definitely seems to be the beta, as I've build the "CoreData + CloudKit" boilerplate app in Xcode 12.x which works, and then built the same with Xcode 13 which breaks.

Did you also notice that when you go back to Xcode 12.x, the old "minimise to refresh" trick doesn't work anymore? You have to close the app and restart it for the iCloud data to get pulled.

It seems to work on the device but not on the simulator.

Has anyone been able to get this to work in Beta 2? Still looks broken to me...

Accepted Answer

I was able to get it to work today after updating to beta 3 versions. I did have to do a erase all contents and settings on the simulator and once that was done data from CloudKit came into my app.

I just tried it out here. Thanks for the info about erasing all contents and settings in the simulator (I would not have thought to try that). It is now working after doing so.

Seems like a new issue in Beta 4 resulting in this error:

"Account Temporarily Unavailable" (1028/2011); "Account temporarily unavailable due to bad or missing auth token"

'Reset All Contents & Settings' on the simulator doesn't appear to fix it this time.

I've also noticed that the current App Store release version of my App which uses NSPersistentCloudKitContainer does not sync properly and crashes after 30 seconds. Nothing has changed other than installing Beta 4. I've submitted a bug report to Apple.

My CloudKit enabled macOS apps are suffering from exact the same error message when running macOS 12 beta 4. This happens on 2 different Macs running the same beta. As if developing for Apple is not already challenging enough.

Fixed for me on iOS 15 Beta 5, out today.

Is Core Data hosted in CloudKit working in Xcode 13?
 
 
Q