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
Search results for
NSPersistentCloudKitContainer
589 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Similar to you both, I also see this error with NSPersistentCloudKitContainer in an existing iOS app which worked fine on iOS 14.5 and Xcode 12. I also notice I am no longer able to use the public database in conjunction with NSPersistentCloudKitContainer, and am forced to use the private database. Perhaps early beta bugs, as @nitramluap said.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
hi, it may be as simple as not turning on history tracking. in my code, i usually have these lines right after creating the NSPersistentCloudKitContainer: // (1) Enable history tracking. this seems to be important when you have more than one persistent // store in your app (e.g., when using the cloud) and you want to do any sort of cross-store // syncing. See WWDC 2019 Session 209, Making Apps with Core Data. guard let persistentStoreDescription = container.persistentStoreDescriptions.first else { fatalError((#function): Failed to retrieve a persistent store description.) } persistentStoreDescription .setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) persistentStoreDescription .setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) hope that helps, DMG
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
Hello I am developing an app with SwiftUI using CoreData and iCloudKit to sync data between platforms. The problem is that the iCloud background update is not being triggered when staying in the application. If I make changes on both systems, the changes are being pushed, however not visible on the other device. I need to reload the app, close the app and open again. I already enabled iCloud capability, background notifications and push notifications. This is my persistentContainer var persistentContainer: NSPersistentCloudKitContainer = { let container = NSPersistentCloudKitContainer(name: Test7) container.loadPersistentStores(completionHandler: {(StoreDescription, error) in if let error = error as NSError? { fatalError(Unresolved error (error), (error.userInfo)) } }) container.viewContext.automaticallyMergesChangesFromParent = true container.viewContext.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy return container }() func saveContext() { let context = persistentContainer.viewConte
Hopefully everyone's recovered from WWDC2021 last week! I've been digging through as much of the new documentation as I can about the NSPersistentCloudKitContainer and sharing over the last couple of days (since I can't get my code working in the XC 13 Beta... looks like a couple of bugs, I think...), and have a question. It appears that this uses Sharing by Record Zone rather than Sharing by Record, which is fine, but... How does this work when you are sharing entities between multiple users? for example... My Db contains a hierarchy of entities under a single root node, and there are multiple such entities (at the moment without overlap between the sub-entities, but I feel like that's just around the corner). Lets call them Entities A, B, and C. Now: Entity A I want to share with Joe. Entity B I want to share with Joe and Sally. Entity C I want to share with Sally and Simon. So, for Entity A I presume that it (and it's sub entities) wind up being represented in a shared record zone (SRZ) of it's ow
My use case is the following: Every user of my app can create as an owner a set of items. These items are private until the owner invites other users to share all of them as participant. The participants can modify the shared items and/or add other items. So, sharing is not done related to individual items, but to all items of an owner. I want to use CoreData & CloudKit to have local copies of private and shared items. To my understanding, CoreData & CloudKit puts all mirrored items in a special zone „com.apple.coredata.cloudkit.zone“. So, this zone should be shared, i.e. all items in it. In the video it is said that NSPersistentCloudKitContainer uses Record Zone Sharing optionally in contrast to hierarchically record sharing using a root record. But how is this done? Maybe I can declare zone „com.apple.coredata.cloudkit.zone“ as a shared zone?
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
Cloud and Local Storage
UI Frameworks
wwdc21-10015
So I tried the public database feature of NSPersistentCloudKitContainer last year but never really got anywhere so I thought i'd try it again this year. However I've still had basically no luck and I figured now might be a good time to try and document the issues I have had. The documentation for this at https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/creating_a_core_data_model_for_cloudkit mentions shouldInitializeSchema which from what I can gather was removed in a beta version a long ** time ago. It appears to now be a method on the container - container.initializeCloudKitSchema(). Ya'll should update this documentation. initializeCloudKitSchema does not work if you have options.databaseScope = .public on the NSPersistentCloudKitContainerOptions. You get a bunch of errors saying No authToken received for asset Turning off the public scope and then calling initializeCloudKitSchema gets you the Record types you need created in the CloudKit console, then r
Can the behavior of NSPersistentCloudKitContainer be described in App Extensions? I have seen Forum entries that describe its behavior in Widgets - it will save data locally, but will not sync that data until the app is opened. This is a pretty major downsides for any apps that use SiriKit Extensions to allow for quick, simple data entry -- not syncing the data until the app is opened (which could be days later) would be a deal breaker. I hope this can be clearly described, and improved (if my understanding is correct) - I've filed a feedback to document this as well: FB9170155
I'm having the same issue with an established app with Xcode 12 & iOS14 using NSPersistentCloudKitContainer. When I try to run the exact code with iOS15 & Xcode 13 (Developer Beta 1 for both) I see the Failed to sync user keys error. I suspect this is an early beta bug so hopefully it will disappear in subsequent betas.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
@Nick: Initialising against the private database as you suggested works on iOS 14.5. It would be really useful if that was in the documentation for initializeCloudKitSchema() if it's not likely to be fixed to support initialising against a public database, to avoid others falling into the trap I did! I've commented to that effect on FB8995024, too. On iOS 15, I can't verify if that's also the case yet because of FB9156476 (the feedback I created during our lab session). For the sake of anyone else who finds this thread, the error that feedback refers to is below. FB9156476 (iOS 15 NSPersistentCloudKitContainer can't sync initial data from server with “Failed to sync user keys”) error: 2021-06-10 21:51:53.672655+0100 MyApp[1230:15921] [error] error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _performSetupRequest:]_block_invoke(955): : Failed to set up CloudKit integration for store: (URL: file:///Users/steve/Library/Developer/CoreSimulator/Devices/59435252-2CF1-4980-8ABB-4B46B21385AA/data/Conta
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
No. NSPersistentCloudKitContainer does not use CKReference.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
Please file bugs for sync in widgets. WidgetKit / ExtensionKit do not allow NSPersistentCloudKitContainer to sync today outside your application's process.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
No. NSPersistentCloudKitContainer will do this for you after the migration completes. If you have a migration where this doesn't occur file a feedback with your various managed object models and we will investigate.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
I have a CoreData-based application, set up with a private CloudKit container and using NSPersistentCloudKitContainer. However, I need additional CloudKit-synchronized data that lives in this container, but not as part of a CoreData scheme. (I.e., I need to read/write some data to the CloudKit container BEFORE initializing the NSPersistentCloudKitContainer. (1) Is this possible? [I'm assuming that the answer is YES.] (2) Since I'm a complete neophyte with CloudKit, can you give me some guidance as to how to set this all up? One way to think about what I want to do is to create a cloud-synchronized UserDefaults that provides consistent default data to all of a user's devices.
In iOS 15, macOS 12, tvOS 15 and watchOS 8 we can finally share NSManagedObjects using NSPersistentCloudKitContainer 🎉 I've been playing around with it and I've managed to share an object from one Apple ID to another. But I'm unable to accept the invite. 😰 If I understand the docs correctly I'm supposed to call func acceptShareInvitations(…) with CKShare.Metadata representing the invite. This metadata should be forwarded to my app using either AppDelegate or SceneDelegate. The problem is that I'm using the SwiftUI App-protocol. I tried setting up an UIApplicationDelegateAdaptor with this code: ivar added @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate AppDelegate implemented class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, userDidAcceptCloudKitShareWith cloudKitShareMetadata: CKShare.Metadata) { assertionFailure() } } The assertionFailure is never called, so my guess is that the SceneDelegate is being called instead. So, how do I im