Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

NSPersistentCloudKitContainer - creates CD_ CKRecord but does not populate values
I have a working app with core data and cloudkit. I changed the NSPersistentContainer to NSPersistentCloudKitContainer. Two NSManagedObjects 'Contact' and 'Location' already exist in core data with relationships along with some other related NSManagedObjects. Populated core data in 'Contact' and saved. Logged in to CloudKit to see it had created CD_Contact and CD_Location CKRecords along with some other CKRecords. Queried CD_Contact it gave error - index name not available on recordName. So created an Index of type Queryable on recordName and searched again. There is no data in CD_Contact. It is supposed to sync data from core data to cloud Kit, but only CKRecord is created but data saved in core data is not synced and populated in CloudKit. How to fix this? On debug I get this: , CD_contactEmail = crsp@gmail; CD_contactEmail_ckAsset, CD_contact, CD_contactEmail, My AppDelegate Code: let container = NSPersistentCloudKitContainer(name: MyModel) let defaultStoreURL = try! FileManager.default.
0
0
1k
Nov ’22
How to handle UX of iCloud Sync with NSPersistentCloudKitContainer?
I'm adding iCloud sync using NSPersistentCloudKitContainer to my production app. When the user firsts downloads the app, they are prompted to create a profile (they basically just choose an icon representing something). There's no email address or anything, and the user can create multiple profiles to track different things. Now that there's iCloud sync, if a user downloads the app on an iPad after using it on their phone, they are still prompted to create a profile. There's no way around this as far as I can tell, because you cannot manually trigger a sync and it sometimes takes a full 5 minutes for NSPersistentCloudKitContainer to decide to sync. How do I handle the UX of this? I don't want the user to have to create a new profile and then delete/merge it once the data comes in, but I can't rely on iCloud syncing in time to handle this case. Any advice would be really appreciated.
0
0
880
Mar ’21
How to add Persistent History Tracking in already existing NSPersistentContainer
As I said in the title I have a core data container created in a custom class static var context: NSManagedObjectContext { let context = persistentContainer.viewContext context.automaticallyMergesChangesFromParent = true return context } // MARK: - Core Data stack static var persistentContainer: NSPersistentCloudKitContainer = { /* The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail. */ let container = PersistentContainer(name: App) container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { print(Unresolved error (error), (error.userInfo)) } }) let description = container.persistentStoreDescriptions.first description?.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) container.persistentStoreDescriptions = [desc
0
0
665
Jan ’20
Suspicious CloudKit Telemetry Data
Starting 20th March 2025, I see an increase in bandwidth and latency for one of my CloudKit projects. I'm using NSPersistentCloudKitContainer to synchronise my data. I haven't changed any CloudKit scheme during that time but shipped an update. Since then, I reverted some changes from that update, which could have led to changes in the sync behaviour. Is anyone else seeing any issues? I would love to file a DTS and use one of my credits for that, but unfortunately, I can't because I cannot reproduce it with a demo project because I cannot travel back in time and check if it also has an increase in metrics during that time. Maybe an Apple engineer can green-light me filing a DTS request, please.
0
0
131
Apr ’25
Prevent data loss from delayed schema deployment
Hi all, I recently discovered that I forgot to deploy my CloudKit schema changes from development to production - an oversight that unfortunately went unnoticed for 2.5 months. As a result, any data created during that time was never synced to iCloud and remains only in the local CoreData store. Once I pushed the schema to production, CloudKit resumed syncing new changes as expected. However, this leaves me with a gap: there's now a significant amount of data that would be lost if users delete or reinstall the app. Before I attempt to implement a manual backup or migration strategy, I was wondering: Does NSPersistentCloudKitContainer keep track of local changes that couldn't be synced doe to the missing schema and automatically reattempt syncing them now that the schema is live? If not, what would be the best approach to ensure this orphaned data gets saved to CloudKit retroactively. Thanks in advance for any guidance or suggestions.
0
0
151
Jun ’25
CoreData • How to perform Lightweight-Migration when using NSPersistentCloudKitContainer?
I am developing an App using CoreData & CloudKit (NSPersistentCloudKitContainer). I am working on an App Update which includes an Update to the CoreData Model. I have created a new Model Version and applied the Changes (including new Properties & Relationships as well as Renaming of Entities & Properties). For Renaming I set the Renaming ID to the old Entity- / Property-Name. These Changes should be supported by Lightweight-Migration. Questions Is there anything else I have to consider when updating a CoreData Model or did I cover all? What about the CloudKit Synchronization? How does CloudKit handle the CoreData Model Update? I read about adding this Method *(initializeCloudKitSchemaWithOptions)* during Development and removing it when deploying to Production. What does this Method do exactly? Thanks a lot for your help in Advance. This is quiet a huge Update and the App does have an existing Userbase, so Migration-Problems are no Option;)
0
0
903
May ’21
Core Data Sharing with iCloud Drive Files
I have an app for client management that stores data in Core Data with an NSPersistentCloudKitContainer. Each manager have their clients in the Core Data Private Database, and each client could have associated files (images, documents, etc) that are stored in app's own folder structure in iCloud Drive. Eventually, a manager can decide if to share a client with another manager, in order to have a shared managed client (readable, or writable+readable by others managers which share the same client). This is done by moving the Client from the Private Database to the Shared Database following the Apple's guidelines: https://developer.apple.com/videos/play/wwdc2021/10015/ This is the structure: The problem is: the database record is shared correctly, but the iCloud Drive Files are not shared (obviously). My goal is to get working the iCloud Drive Client Files (every client has a single Folder) with the minimum effort from the user. I cannot get working the iCloud Drive Sharing from my app, only the Core Da
0
0
902
Oct ’21
Advice on sharing data between apps NSPersistantCloudkit container or App groups or both?
I have several different apps that I'd like to share a personal core data store with on the same device and across devices. I've been experimenting with NSPersistentCloudKitContainer, which seems to work, but it can take a while to sync and it's not clear when it has. I have also experimented with using app groups where the SQLite file is placed in the app group so that changes are immediately available to other apps on the device. My question is whether it is better to do one or the other or both. Will two apps open on the same device accessing the shared SQLite cause conflict issues? Do I even need to sync data with cloudKit if I'm already syncing with a shared group? Using NSPersistentCloudKitContainer alone means that each app will be syncing its own copy of the data locally, which doesn't seem very efficient and again I don't know if it's synched when I open the other app up. But I have seen conflicts when i have both apps open at the same time. Is there a foolproof way to prevent confl
0
0
702
Jun ’22
I other any NSPersistentCloudKitContainer event notification exist for iOS 13?
for iOS 14+ there is notification to let you know that your data exported and imported and other events type. `` if let cloudEvent = notification.userInfo?[NSPersistentCloudKitContainer.eventNotificationUserInfoKey] as? NSPersistentCloudKitContainer.Event }`` but to make compatibility my app with iOS 13, if there any event type exist like above for NSPersistentCloudKitContaine?
0
0
1.1k
May ’22
NSPersistentCloudkitContainer setup - merge behavior - contexts
Is it ok to use automaticallyMergesChangesFromParent to true for a managed object context that pins its query generation to current? I have heard from a few sources that in most cases, it’s not recommended to set automaticallyMergesChangesFromParent to true for a managed object context that pins its query generation to current. A source I have seen says: When you pin a managed object context to a specific query generation, you’re explicitly telling the context to view the data as it existed at the time of that generation token (often referred to as a snapshot). This ensures that the context is isolated from any subsequent changes made by other contexts or background tasks. But this may Conflict with Automatic Merging because: The purpose of setting automaticallyMergesChangesFromParent to true is to have the context automatically merge changes from the parent (e.g., background or main context) into itself whenever the parent context saves changes. This behavior conflicts with the concept of a pinned query gene
Topic: UI Frameworks SubTopic: General
0
0
290
Oct ’24
Core Data modifications not saved in two of three tables
I'm a bit lost because of a problem I never experienced before, however, I have a suspicion. I use Core Data for data storage and DB Browser for SQLite for inspecting the database running in the Simulator. Here's the relevant function where all Core Data handling happens: /** Creates a new ComposedFoodItem from the ComposedFoodItemViewModel. Creates the related FoodItem and the Ingredients. Creates all relationships. - Parameter composedFoodItemVM: The source view model. - Returns: A Core Data ComposedFoodItem; nil if there are no Ingredients. */ static func create(from composedFoodItemVM: ComposedFoodItemViewModel, generateTypicalAmounts: Bool) -> ComposedFoodItem? { debugPrint(AppDelegate.persistentContainer.persistentStoreDescriptions) // The location of the .sqlite file let moc = AppDelegate.viewContext // Create new ComposedFoodItem (1) let cdComposedFoodItem = ComposedFoodItem(context: moc) // No existing composed food item, therefore create a new UUID cdComposedFoodItem.id = UUID() // Fill data cdCo
1
0
455
Jan ’24
CloudKit + SwifData setup
Hey folks, I'm having an issue where iCloud sync is only working in the Development environment, not on Prod. I have deployed the schema to Prod through the CloudKit console, although I did it after the app went live on the AppStore. Even though the two schema are identical, iCloud sync just doesn't work on Prod. Things I tried on the code side: Initially I did the most basic SwiftData+CloudKit setup: var modelContainer: ModelContainer { let schema = Schema([Book.self, Goal.self]) let config = ModelConfiguration(isStoredInMemoryOnly: false, cloudKitDatabase: doesUserSyncToiCloud ? .automatic : .none) var container: ModelContainer do { container = try ModelContainer(for: schema, configurations: config) } catch { fatalError() } return container } var body: some Scene { WindowGroup { AnimatedSplashScreen { MainTabView() } } .modelContainer(modelContainer) } This is enough to make iCloud sync work at the Development level. Then when I noticed the issues on Prod I did some digging and found this on the Docs (https
0
0
379
Nov ’24
CoreData changes made aren’t showing in Data in CloudKit Dashboard
i am using NsPersistentCloudkitContainer with CoreData and CloudKit to manage my database. When I save data to the managedObjectContext I see my data model ‘Post’ added in Schema as a Record Type in the CloudKit Dashboard , but when I go to the Data section I still don’t see any data added. can anyone help why this is happening?
0
0
450
Jul ’20
CloudKit UICloudSharingController `recordChangeTag specified, but record not found`
Hello! I'm using NSPersistentCloudKitContainer for storing data and UICloudSharingController for sharing. Here's how UICloudSharingController is created: func share(_ record: Record, avatar: UIImage) { let controller = shareControllerForRecord(record, avatar: avatar) controller.delegate = self controller.popoverPresentationController?.sourceView = self.view controller.popoverPresentationController?.permittedArrowDirections = [] present(controller, animated: true) } func shareControllerForRecord(_ record: Record, avatar: UIImage) -> UICloudSharingController { if let share = share(for: record) { let controller = UICloudSharingController(share: share, container: self.cloudKitContainer) return controller } else { let controller = UICloudSharingController { [weak self] (controller, completion: @escaping (CKShare?, CKContainer?, Error?) -> Void) in guard let self = self else { return } self.persistentContainer.share([record], to: nil) { objectIDs, share, container, error in if let share = share { rec
0
0
810
Oct ’22