Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

CloudKit and CoreData synchronization
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
3
0
2.5k
Jun ’21
Reply to CloudKit and CoreData synchronization
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:
Jun ’21
Reply to Initialising CloudKit schema on public database fails for in Core Data with multiple strings (rdar://FB8995024)
@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
Jun ’21
NSPersistentCloudKitContainer: Migrating multiple devices with data changes in between
What is the expected / best strategy to migrate a synced Core Data model to a new version? The issue: A new app version with a new Core Data model introducing new attributes or entities. DeviceA installs the update and edits data with new values and creates new entities. DeviceB is still used and downloads these changes. The unknown attributes and entities are ignored, but the HistoryTracking gets updated. A few days later DeviceB gets the update. The missing attributes and entities are not downloaded, as the history is up to date. __ The issue exists with iOS 13, I hoped for iOS 14 to introduce a strategy. I tried with the first iOS 14 beta, but it is at least not handled automatically. From the visible API changes I don't see a way to handle this specifically. Not sure if the talks will reveal anything about it. Will apply for a lab session and would like to get as much input to prepare before that might take place.
9
0
2k
Jun ’21
How to migrate NSPersistentCloudKitContainer to App Group to access in Widget
I have shipped an app that utilizes Core Data in CloudKit viaNSPersistentCloudKitContainer. I now want to add a widget that can query for the current data to display. It's my understanding you need to migrate this to a new location available to a shared App Group. How do you do this? container = NSPersistentCloudKitContainer(name: AppName) container.loadPersistentStores { description, error in //handle error } container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy container.viewContext.automaticallyMergesChangesFromParent = true
1
0
1.4k
Jun ’21
NSPersistentCloudKitContainer: How to re-fetch a record from CloudKit?
Is there a way to ask NSPersistentCloudKitContainer to update a local managed object’s values by refetching them from CloudKit? Here is my scenario: Let’s say I have a simple Address Book app that stores first name, last name, and phone number. I use NSPersisentCloudKitContainer to sync the data across a user’s devices. Let’s say a user installs the app on their iPhone and iPad. They add a bunch of records. All is working well. Now, I create version 2 of the app that adds a Notes field. The user installs version 2 on their iPhone, but have not updated their iPad yet. The user then adds some notes to existing records. Obviously, the user’s iPad will not download these notes since they have not updated to the version of the app that supports that field. Now, when the user finally installs version 2 of the app on their iPad, I want to ask NSPersistentCloudKitContainer to fetch the notes fields for the records that have been updated. However, I don’t see a way to do this. Of course, I could get
1
0
972
Jun ’21