Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to Does SwiftData currently supports data sharing among multiple users through iCloud?
SwiftData + CloudKit integration doesn’t support CloudKit sharing as of today. I haven’t tried to implement SwiftData + CloudKit sharing with my own effort, but based on my understanding on the technologies, if the object graph to be shared is relatively complicated, I'd consider sticking with NSPersistentCloudKitContainer (Core Data), because NSPersistentCloudKitContainer interacts with Core Data, and using SwiftData adds another layer of complexity. If the data to be shared is quite simple, such as a small set of values without relationships, and I have built my app with SwiftData, I might consider using CloudKit API directly to implement the sharing flow. That way, I completely control the synchronization and sharing process, and can share any data type, including SwiftData. For the first option, you can start with the following sample: Sharing Core Data objects between iCloud users The second option may turn out a bit involved. You can start with the technical resources mentioned in the
Oct ’24
Reply to SwiftData iCloud sync breaks after disabling and re-enabling iCloud
Thanks for filing the feedback report. Other than that, if you would like to figure out what really happens when synchronization fails, please follow this technote to capture and analyze a sysdiagnose: TN3163: Understanding the synchronization of NSPersistentCloudKitContainer I am guessing that it is the system delaying or throttling the synchronization for some reason (reasonable or not), and am curious to see your findings. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’24
Reply to SwiftData iCloud sync breaks after disabling and re-enabling iCloud
... was cancelled because there is already a pending request of type 'NSCloudKitMirroringExportRequest... This message doesn't quite matter, as discussed in Execute the export. After some time the sync fails again for no obvious reason and here is the error that appears in the console for a Mac app To get to the bottom in this situation, you might still want to look into a sysdiagnose. The whole analysis process is discussed in TN3163: Understanding the synchronization of NSPersistentCloudKitContainer. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’24
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
How to "Keep on My iPhone" after disabling iCloud for my app using Core Data
I have Core Data setup with a NSPersistentCloudKitContainer as my container, I've added a container identifier and I see my data on CloudKit's database here when I use Act As iCloud Account. Here's what I have under capabilities in Xcode However, on my device when I go to Settings > Apple Account > iCloud > Saved to iCloud and switch off my app, all the data saved to Core Data is removed. I suspected this working as intended. When I switch it back on, all the data comes back. However (x2), the support page here says it should remain on the device: When you turn it off, the app no longer connects with iCloud, so your data exists only on your device Am I missing something in how I integrated Core Data in Xcode? Do I need to explicitly configure something with Apple's SDK to get the behavior described in the support page? I've noticed for some of Apple's apps, when you switch off iCloud there's an action sheet asking what you'd like to do with the local data. I figured this was Apple's magic wi
1
0
1k
Oct ’24
SwiftData ModelConfigurations always sync to iCloud if one of them has iCloud enabled
I'm facing a weird issue with SwiftData. I want to have one database that's local to the device and one that syncs to iCloud. In this example, LTRLink should be synced via iCloud while LTRMetadata should stay on-device only. I've it configured like the following: let schema = Schema([LTRLink.self, LTRMetadata.self]) let cloudkitConfiguration = ModelConfiguration(Remote, schema: schema, url: FileManager.remoteDatabaseFolderURL.appending(path: Remote.sqlite), cloudKitDatabase: .private(iCloud.com.xavimoll.abyss3)) let localConfiguration = ModelConfiguration(Local, schema: schema, url: FileManager.localDatabaseFolderURL.appending(path: Local.sqlite), cloudKitDatabase: .none) return try ModelContainer(for: schema, configurations: [cloudkitConfiguration, localConfiguration]) For some reason, when I create the iCloud schema, both models end up appearing as records on iCloud. I create the schema like this: let schema = Schema([LTRLink.self, LTRMetadata.self]) let cloudkitConfiguration = ModelConfiguration(Remote, sc
1
0
652
Oct ’24
iOS 18 Core Data and CloudKit Sync Issue with NSPersistentCloudKitContainer
After upgrading to iOS 18, my Core Data stack using NSPersistentCloudKitContainer in a shared App Group container stopped syncing correctly. The persistent store configuration, which previously worked in iOS 17, now experiences delayed or missing sync updates between devices. Then the app freezes and writes terminal the same error detail (which I provided) too many times. The debug logs from the CloudKit mirroring delegate (NSCloudKitMirroringDelegate) show repetitive notifications but no updates in persistent history. Additionally, the persistent history tracking key appears unresponsive to local changes, causing transactions to fail in updating or syncing as expected. Key setup details: Core Data is set up within an App Group container using NSPersistentCloudKitContainer. NSPersistentHistoryTrackingKey and NSPersistentStoreRemoteChangeNotificationPostOptionKey options are set to true. Any insights into changes in iOS 18 Core Data or CloudKit handling with NSPersistentCloudKitContainer
0
0
636
Oct ’24
Reply to Core Data CloudKit stops syncing after incomprehensible archive error
This error message your post provided indicates that Core Data failed to unarchive the import request (NSCloudKitMirroringImportRequest). Archiving / unarchiving an import / export request is a Core Data internal logic, and so I agree your assessment that it is not about your code. The feedback report you filed (FB10392936) doesn't mention the error message, and so I'd suggest that you file a new one to specifically report the error – If you do so, please share your report ID here for folks to track. Regarding FB10392936, you most likely hit CloudKit throttles. For more information of this topic, see the following documentations: TN3162: Understanding CloudKit throttles Understand system throttles. When uploading a big data set and hitting CloudKit throttles, the only thing you can do is to lower the CloudKit operation rate. When using Core Data + CloudKit, however, you don't control how NSPersistentCloudKitContainer synchronizes data. Based on today's API, the only thing you can do is to somehow con
Oct ’24
Reply to How to "Keep on My iPhone" after disabling iCloud for my app using Core Data
However, on my device when I go to Settings > Apple Account > iCloud > Saved to iCloud and switch off my app, all the data saved to Core Data is removed. I suspected this working as intended. Yeah, this is an as-designed behavior. Basically, NSPersistentCloudKitContainer removes the local data from the device in that case for privacy reason, and it doesn't expose any API for developers to configure the behavior. I discussed the behavior NSPersistentCloudKitContainer responds to user switching in the following post: NSPersistentCloudKitContainer losing data From user's perspective, switching to a new user may be different from disabling the Saved to iCloud setting, but CloudKit doesn't handle the two cases in a different way, as far as I know. Having said that, if you believe that NSPersistentCloudKitContainer shouldn't behave that way, please file a feedback report with your concrete use case – If you do so, please share your report ID here. Best, —— Ziqiao Chen 
Nov ’24
NSPersistentCloudKitContainer not saving 50% of the time
I'm using NSPersistentCloudKitContainer to save, edit, and delete items, but it only works half of the time. When I delete an item and terminate the app and repoen, sometimes the item is still there and sometimes it isn't. The operations are simple enough: moc.delete(thing) try? moc.save() Here is my DataController. I'm happy to provide more info as needed class DataController: ObservableObject { let container: NSPersistentCloudKitContainer @Published var moc: NSManagedObjectContext init() { container = NSPersistentCloudKitContainer(name: AppName) container.loadPersistentStores { description, error in if let error = error { print(Core Data failed to load: (error.localizedDescription)) } } #if DEBUG do { try container.initializeCloudKitSchema(options: []) } catch { print(Error initializing CloudKit schema: (error.localizedDescription)) } #endif moc = container.viewContext } }
2
0
406
Nov ’24
Display name for CloudKit container in the "Manage Storage" view of Settings
How can I set the display name of the CloudKit container in Settings -> iCloud -> Manage Storage. I have multiple containers, some legacy, and some for certain modules that are shared among a suite of apps. The problem is all Containers show the same name so it is not possible to advise a user which containers are safe to delete. I am using NSPersistentCloudKitContainer.
1
0
294
Nov ’24
Core Data Error - "NSCocoaErrorDomain" - code: 134060
Hi, I am implementing the synchronisation of SwiftData with CloudKit as described in the Apple Documentation titled - Syncing model data across a person’s devices. My app runs fine on iPhone without activating CloudKit under Signing and Capabilities option. But when activated, I get a CoreData error with a code: 134060. My app is in development stage. The following is the code snippet for your reference taken from the main structure adopting the App protocol. init() { do { #if DEBUG let schema = Schema([ Debit.self, Credit.self, ]) let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false) // Use an autorelease pool to make sure Swift deallocates the persistent // container before setting up the SwiftData stack. try autoreleasepool { let desc = NSPersistentStoreDescription(url: modelConfiguration.url) let opts = NSPersistentCloudKitContainerOptions(containerIdentifier: iCloud.com.sureshco.MyFirstApp) desc.cloudKitContainerOptions = opts // Load the store synchronously so it compl
0
0
545
Nov ’24
Reply to MacOS CloudKit production environment is not working properly
I have recently been experiencing issues in the Production Environment as well, although I cannot confirm if it is the same situation. My app is Mac only. I am adding iCloud support to an existing app that is already on the Mac App Store. I am testing such support via TestFlight builds. I am not using SwiftData but traditional Core Data with NSPersistentCloudKitContainer. – When making use of the Production Environment, only partial synchronization took place. This has not been an issue when run in the Development Environment. This occurred multiple times even when testing using accounts with different App IDs. My only thought was that perhaps iCloud also needed to be enabled as a Capability in Certificates, Identifiers & Profiles. That did not end up being the case. However, I was surprised to see that two iCloud Containers were enabled for this app even though only one was selected for the target in Xcode. After removing the unused container from the list and saving, I performed the following a
Nov ’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