Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to NSPersistentCloudKitContainer - Import failed because applying the accumulated changes hit an unhandled exception
Update for anyone else with this issue. Here is the reply I have received from Framework engineers in response to bug report We have additional information, the root cause of this issue is a large number of incoming images in the same import. You can work around this by syncing your images with CloudKit directly via a CKRecord you own (instead of letting NSPersistentCloudKitContainer do it). We will continue to improve the performance of NSPersistentCloudKitContainer and followup again in this feedback report when the issue is resolved.
Mar ’22
NSPersistentCloudKitContainer Bug
I have been excited to add NSPersistentCloudKitContainer's share functionality to my app but I've noted a few thing I suspect are bugs: -When using share() on a NSManagedObject the share record is set up in a new zone. However, the root NSManagedObject's record is not being updated with the relationship linkage to the shared record. -Secondly, when you revoke a share, the cloudkit.share record is removed from iCloud, but not in the local data stores. This makes the fetchShares() method ineffective for detecting a missing cloudkit.share record. In order to re-share the root object the developer must call out to iCloud directly using the old methods to be sure if the share exists or not. I am using the code from Apple's 'Synchronizing a Local Store to the Cloud' sample. It would be nice if they added support for revoking shares into this sample and addressed these issues.
8
0
6.0k
Apr ’22
Cannot migrate store in-place: CloudKit integration forbids renaming
Background Core Data driven app, successfully using NSPersistentCloudKitContainer for some time. App is written 100% SwiftUI, currently targeting iOS and macOS targets. Development only, no production release yet. Error... ... Fatal error: Unresolved error Error Domain=NSCocoaErrorDomain Code=134110 An error occurred during persistent store migration. ... reason=Cannot migrate store in-place: CloudKit integration forbids renaming 'foodServes' to 'foodPortions'. Older devices can't process the new relationships. An unusual problem for me... the renaming occurred between version 7 and version 8 of the Core Data model and this is version 13. So if I revert back to version 12, there is no issue. It is only when I add the new Entity in model version 13 that the error occurs. The new entity incudes a relationship back to two other existing entities, but not the Food entity that contains the foodServes -> foodPortions renamingID. To be clear, the error relates to a renamingID that was implemented in the
1
0
2.0k
Feb ’22
Reload NSPersistentCloudKitContainer from a SwiftUI View - MVVM
How can I reload the NSPersistentCloudKitContainer from a SwiftUI View? I have a SwiftUI + MVVM + CloudKit app that successfully syncs to CloudKit but what I would like to be able to do is reload the NSPersistentCloudKitContainer from some View in the app to be able to evaluate if the app should sync to CloudKit or not by setting the cloudKitContainerOptions to nil (description.cloudKitContainerOptions = nil) if the user doesn't want to sync. In other words, I need to reload the code inside the init() method in the CoreDataManager file when a method in the View Model is called. See the code and comments below. Here is the code... Core Data Manager class CoreDataManager{ static let instance = CoreDataManager() let container: NSPersistentCloudKitContainer let context: NSManagedObjectContext init(){ container = NSPersistentCloudKitContainer(name: CoreDataContainer) guard let description = container.persistentStoreDescriptions.first else{ fatalError(###(#function): Failed to re
1
0
790
Feb ’22
NSPersistentCloudKitContainer exclude relationship from share
I am trying to add CloudKit sharing to my app using the new iOS 15 share method https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer/3746834-share In the app there are 3 core data entities (Folder, Item, Comment) with the following relationships: A Folder contains many Items An Item has many Comments I want to use CloudKit to share just the Item entity, not any of its relationships. Is this possible to do with the share(_:to:completion:) method? Currently, when I pass an Item to the share method it also includes the Folder and Comments in the CKShare. How do I prevent this?
1
0
977
Feb ’22
Reply to Avoid Duplicate Records with CloudKit & CoreData
NSPersistentCloudKitContainer doesn’t support unique constraints today. To make sure that a record is unique across devices, you need to implement your own mechanism. In case you are interested in doing that, I have a sample project (I use it as my testbed) that may help: Sharing Core Data Objects Between iCloud Users It is a SwiftUI project that supports iOS and watchOS, and covers the following topics: Creating the CloudKit Schema for Apps Setting up the Core Data Stack Sharing a Core Data object Detecting Relevant Changes by Consuming Store Persistent History Removing Duplicate Data Implementing a Custom Sharing Flow #4 and #5 are probably the most relevant to your question. Feel free to provide your feedback here so I can improve the project and hopefully better help.
Feb ’22
Cloudkit - Coredata and multiples database
Today, I'm working without cloudkit (all data are in a local Coredata), with one database on my Xcode project but with 2 containers on app.delegate : one for a test environment : with storeURL ---> test.sqlite one for a production environment : with storeURL --> production.sqlite Everything is ok, the test data, is really separate from production data. Now, I try to use cloudkit functions : I change NSPersistentContainer to NSPersistentCloudKitContainer it's working and I could use data on 2 iPads. BUT if I switch the test to the prod, now the data from test environnement is duplicate on the production environnement. what mistake am I making? How could I use my two storeURL with cloudkit coredata? Thanx for your help.
2
0
723
Jan ’22
Reply to Siri Shortcuts with SwiftUI and Core Data
Short Answer: It is a bug. Just run (command + R) your app then stop it. Then talk to your Siri. You will see the new Item is added to your list. I think debugger stops core data to be updated from external events. Long Answer: I also tried many different approaches in the web and nothing worked. But here is the simplest code that I could add item to my list via Siri. Simply setup your PersistenceController public struct PersistenceController { public static let shared = PersistenceController() public let container: NSPersistentCloudKitContainer init(inMemory: Bool = false) { container = NSPersistentCloudKitContainer(name: YourApp.) if inMemory { container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: /dev/null) } else { let storeURL = AppGroup.coredata.containerURL.appendingPathComponent(YourApp.sqlite) let description = NSPersistentStoreDescription(url: storeURL) container.persistentStoreDescriptions = [description] } container.loadPersistentStores(completionHandler: { (sto
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
How to turn On/Off iCloudKitSync on a SwiftUI application
I'm trying to give the user the ability to decide whether they want to sync to CloudKit or not by turning On or Off a Switch located somewhere in the app settings screen but I'm not sure how to do it in SwiftUI. The following code successfully stops the sync to CloudKit by setting the cloud kit container options to nil description.cloudKitContainerOptions = nil. class CoreDataManager{ static let instance = CoreDataManager() let container: NSPersistentCloudKitContainer let context: NSManagedObjectContext init(){ container = NSPersistentCloudKitContainer(name: CoreDataContainer) guard let description = container.persistentStoreDescriptions.first else{ fatalError(###(#function): Failed to retrieve a persistent store description.) } description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) description.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) description.cloudKitContainerOptions = nil container.loadPersistentStores { (descri
2
0
1.5k
Jan ’22
Fetch data from CloudKit to app when app is in background
Hello I have an app that uses Core Data with CloudKit to store data. When I am in the app (using the app) and create some new data on an other device, the data is fetched in a few seconds and I see it immediately, however if I am not using the app and create some new data on an other device, I have to enter the app and then the data starts fetching, is there a way to fetch data even if I am not using the app. Here is my core data stack: import CoreData import Combine class PersistenceController { static let shared = PersistenceController() let container: NSPersistentCloudKitContainer init() { container = NSPersistentCloudKitContainer(name: CoreData) guard let fileContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: APP_GROUP_NAME)?.appendingPathComponent(CoreData.sqlite) else { fatalError(Shared file container could not be created.) } let storeDescription = NSPersistentStoreDescription(url: fileContainer) storeDescription.setOption(true as NSNumber, forKey: NSP
1
0
1.8k
Jan ’22
Old local persistent store to new CloudKit store- lightweight migration
I have a new model which syncs to cloudkit. I'have to migrate my old core data store which is local to the new model which will store in cloudkit. I'm not sure how to perform this migration. The container is initialised correctly and the Mapping Model is mapping my entities and attributes correctly. There are no errors. Yet, I do not see my old records upon fetching. I found this lines of code here... NSDictionary *optionsDictionary = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, <#Ubiquitous content name#>, NSPersistentStoreUbiquitousContentNameKey, nil]; However, I'm not sure where to add it. Since, I had created a new project folder with core data + CloudKit (and imported the old model), this is the method i got in AppDelegate which initialises the store... - (NSPersistentCloudKitContainer *)persistentContainer { // The persistent container for t
5
0
754
Jan ’22
How to get NSPersistentCloudKitContainer to sync in background
Is it possible for an app using NSPersistentCloudKitContainer to enable sync in the background, if so, how? Install app on your iPhone and iPad, create some data, it automatically syncs to both and life is good Close the iPad app Modify the data on iPhone Desired behavior: The backgrounded iPad app should sync (even if it takes a while) and be informed that its local database has finished syncing or similarly that changes were made. The use case is I want to reload my widget when data changes so it's up-to-date, so I need my app to sync it in the background, then notify when it's complete to be able to trigger the widget reload. I am concerned it will be a poor widget experience if it's always showing stale data until they manually open the app to initiate sync - kind of defeats the purpose of widgets. ha According to this post, they found sync is never run in the background. Is this not the case, or has it changed in iOS 15? Thanks!
2
0
1.7k
Dec ’21
CoreData + CloudKit: Cocoa-Error 134419
Hi, Some of my users are experiencing synchronization issues when using the NSPersistentCloudKitContainer in CoreData. My app is listening to any errors that occur during the synchronization with the NSPersistentCloudKitContainer.eventChangedNotification Notification. Before I just got Cocoa-Errors 2 or 3 which indicate a bad network connection or something similar. Now I received reports with a Cocoa-Error 134419. Does anyone know what this error code means? Maybe someone from the Core Data team could have a look at this. Thanks a lot, Alexander
1
0
1.9k
Dec ’21
What should be the expected user experience from an app that uses CloudKit/Sync
I have a SwiftUI app where I would like to enable NSPersistentCloudKitContainer to start using CloudKit and be able to sync the content of the app between multiple devices, but I'm not sure how to handle the user experience. Should this be a feature that the user turns On and Off in the app settings screen or does the user expects the syncing mechanism to work by default without having to do anything, can someone please share your experience on how you implemented CloudKit/Sync in your app. Do I need to offer a login mechanism so the user logs in? Should I include an On/Off option so the user decides if they want the sync option or not? In general, can someone be so kind and explain what the user experience should be when an app provides ClouldKit/sync? FYI - I'm not asking how to implement CloudKit sync I already know what it is and how it works. I just need to know what the expedition is from an app the provides that feature. Thanks!
1
0
740
Dec ’21