Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to CloudKit sync stopped working with error „You can't save and delete the same record"
You can't save and delete the same record Assuming that you are using Data + CloudKit, I am guessing that this can be triggered by your code and data. Consider the following configuration as an example: Delete Rule: cascade articleA.associatedArticles -> [articleB, articleC...] articleB.associatedArticles -> [articleA, articleC...] If you delete articleA, Core Data will delete articleB due to 1 and 2, and change articleB due to 3 at the same time. You can review your code to see if the above case can happen. When you use Core Data + CloudKit, NSPersistentCloudKitContainer configures and performs the CloudKit operations without any involvement of your code, and so it is worth filing a feedback report for the Core Data team to investigate why the case isn't handled – If you do so, please share your report ID here. Already have a mirrored relationship registered for this key Based on the (more) information you provided to DTS, this seems to indicate that you has a reflexive relationship (a relatio
Jan ’25
Reply to How to let iCloud sync across the devices without launching the app at midnight?
Thanks for sharing. SwiftData + CloudKit is based on NSPersistentCloudKitContainer as of today, which doesn't do any synchronization if the app is not launched. Even if the app is running, it will be up to the system to decide when to synchronize data. There is no way for an app to force NSPersistentCloudKitContainer to synchronize with CloudKit. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jan ’25
Reply to CoreData + CloudKit
I'd firstly point you the following technotes, which I believe will give you the whole picture about how Core Data + CloudKit works: TN3163: Understanding the synchronization of NSPersistentCloudKitContainer TN3164: Debugging the synchronization of NSPersistentCloudKitContainer TN3162: Understanding CloudKit throttles Concretely to your questions: What are the solutions I have when the user first loads the app? How to force CoreData to query directly cloudKit? There is no API for an app to speed up the initial synchronization as of today. If there is a lot of data on the server, the synchronization will indeed take long time. I'd suggest that you file a feedback report against that. There is no API to force CoreData to import from CloudKit, and that is as-designed, as discussed in the technotes mentioned above. Does CoreData + CloudKit + NSPersistentCloudKitContainer will download the whole CloudKit database in my local, is that good???? When using NSPersistentCloudKitContainer
Jan ’25
CoreData + CloudKit
I am having problems when I first loads the app. The time it takes for the Items to be sync from my CloudKit to my local CoreData is too long. Code I have the model below defined by my CoreData. public extension Item { @nonobjc class func fetchRequest() -> NSFetchRequest { NSFetchRequest(entityName: Item) } @NSManaged var createdAt: Date? @NSManaged var id: UUID? @NSManaged var image: Data? @NSManaged var usdz: Data? @NSManaged var characteristics: NSSet? @NSManaged var parent: SomeParent? } image and usdz columns are both marked as BinaryData and Attribute Allows External Storage is also selected. I made a Few tests loading the data when the app is downloaded for the first time. I am loading on my view using the below code: @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: Item.createdAt, ascending: true)] ) private var items: FetchedResults var body: some View { VStack { ScrollView(.vertical, showsIndicators: false) { LazyVGrid(columns: columns, spacing: 40) { ForEach(items, id: .self) { item in
1
0
922
Jan ’25
Reply to MAJOR Core Data Issues with iOS 18 and sdk - Data Missing for many users?!
Hi, Thanks for your response. I don't think we do any of the things you are concerned about. Here is some of the code I use to set up the CoreData/Cloudkit stack and have been using this for a few years now. Nothing changed here in at least 12 months (I am not exactly a piker in this realm :) : class CoreDataUtil: NSObject { @objc var pc = NSPersistentCloudKitContainer(name:iphemeris) private lazy var historyRequestQueue = DispatchQueue(label:history) let coreDataLogSubsystem = com.iPhemeris.coreData let coreDataLogger = Logger(subsystem:com.iPhemeris.coreData, category:Cloudkit) @objc var useiCloud:Bool = userSettings.bool(forKey:UseIcloudKey) { didSet { userSettings.set(useiCloud, forKey:UseIcloudKey) if(pc.persistentStoreCoordinator.persistentStores.count > 0) { let store = pc.persistentStoreCoordinator.persistentStores[0] do { try pc.persistentStoreCoordinator.remove(store) } catch { coreDataLogger.log(*** CoreDataUtil toggle use iCLoud ON/OFF FAILED: (error, privacy:.public)) } } self.initCor
Jan ’25
Reply to Database not deploying to CloudKit
Did you ever run your app and save some data to the CloudKit-backed Core Data store? NSPersistentCloudKitContainer only creates the custom zone when there is data. Also, you need to initialize the CloudKit schema, if not yet. See Create the CloudKit schema for the more details. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jan ’25
Reply to SwiftData data duplication
SwiftData + CloudKit is currently based on NSPersistentCloudKitContainer. Duplicate data can be generated if you have multiple app instances uploading a same piece of data, as discussed in Remove duplicate data. NSPersistentCloudKitContainer doesn't support unique constraints as of today, and so you will need to remove duplicate data with your own algorithm and code. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jan ’25
Reply to Disable SwiftData CloudKit sync when iCloud account is unavailable
To work around this and improve the user experience, we want to use CKContainer.accountStatus to check if the user has an available iCloud account, and if not, disable the CloudKit sync before it erases the local data. This is fine but doesn't completely solve your problem: While your app is running, a user can launch Settings.app and log out their iCloud account or turn off iCloud for your app, which still triggers an account change, but your app can't respond because it only checks the account availability at the beginning of a launch session. You can probably observe the CKAccountChanged notification, but then there may have a race – NSPersistentCloudKitContainer may still erase the data before you release the current model container. However, we are receiving regular reports from users for whom the system has incorrectly indicated that the app's access to iCloud is unavailable, even when the user hasn't logged out or toggled off permission to access iCloud. This triggers the behavior to clear the
Jan ’25
Disable SwiftData CloudKit sync when iCloud account is unavailable
I have a widely-used app that lets users keep track of personal data. This data is persisted with SwiftData, and synced with CloudKit. I understand that if the user's iCloud account changes on a device (for example, user logs out or toggles off an app's access to iCloud), then NSPersistentCloudKitContainer will erase the local data records on app launch. This is intentional behavior, intended as a privacy feature. However, we are receiving regular reports from users for whom the system has incorrectly indicated that the app's access to iCloud is unavailable, even when the user hasn't logged out or toggled off permission to access iCloud. This triggers the behavior to clear the local records, and even though the data is still available in iCloud, to the user, it looks like their data has disappeared for no reason. Helping the user find and troubleshoot their iCloud app data settings can be very difficult, since in many cases the user has no idea what iCloud is, and we can't link them directly to the c
1
0
1.1k
Jan ’25
Reply to NSPersistentCloudKitContainer Import failed (incomprehensible archive)
Our general set of debugging / inspection Tech Notes are: https://developer.apple.com/documentation/technotes/tn3163-understanding-the-synchronization-of-nspersistentcloudkitcontainer https://developer.apple.com/documentation/technotes/tn3162-understanding-cloudkit-throttles https://developer.apple.com/documentation/technotes/tn3164-debugging-the-synchronization-of-nspersistentcloudkitcontainer If you set an exception breakpoint in Xcode you can probably capture call stack where the keyed archiver exception is thrown. That, the store files from the device having issues, and a sysdiagnose would make a good feedback report for further investigation. We include instructions for capture a sysdiagnose in TN3163.
Dec ’24
Field recordName is not marked queryable
I'm using NSPersistentCloudKitContainer and in the CloudKit dashboards I have added indexes for all my records modifiedTimestamp queryable, modifiedTimestamp sortable and recordName queryable. But I'm still getting this warning message in the console. error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _importFinishedWithResult:importer:](1400): : Import failed with error: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate recoverFromError:](2312): - Attempting recovery from error: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _recoverFromError:withZoneIDs:forStore:inMonitor:](2622): - Failed to recover from error: CKErrorDomain:12 Recovery encountered the following error: (null):0 error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate resetAfterError:andKeepContainer:](612): - resetting internal state after error: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _requestAbortedNotInitialized:](2200): - Never successfully initialized and cannot execute request ' A3F
2
0
1k
Dec ’24
SwiftData + CKSyncEngine
Hi, I'm building a habit tracking app for iOS and macOS. I want to use up to date technologies, so I'm using SwiftUI and SwiftData. I want to store user data locally on device and also sync data between device and iCloud server so that the user could use the app conveniently on multiple devices (iPhone, iPad, Mac). I already tried SwiftData + NSPersistentCloudKitContainer, but I need to control when to sync data, which I can't control with NSPersistentCloudKitContainer. For example, I want to upload data to server right after data is saved locally and download data from server on every app open, on pull-to-refresh etc. I also need to monitor sync progress, so I can update the UI and run code based on the progress. For example, when downloading data from server to device is in progress, show Loading... UI, and when downloading finishes, I want to run some app business logic code and update UI. So I'm considering switching from NSPersistentCloudKitContainer to CKSyncEngine, because it
3
0
1.4k
Dec ’24
Share sheet configuration
I'm trying to configure the share sheet. My project uses techniques from the Apple Sample project called CoreDataCloudKitShare which is found here: https://developer.apple.com/documentation/coredata/sharing_core_data_objects_between_icloud_users# In this sample code there's a PersistenceController which is an NSPersistentCloudKitContainer. In the PersistenceController+SharingUtilities file there are some extensions, and one of them is this: func configure(share: CKShare, with photo: Photo? = nil) { share[CKShare.SystemFieldKey.title] = A cool photo } This text A cool photo seems to be the only bespoke configuration of the share sheet within this project. I want to have more options to control the share sheet, does anyone know how this might be achieved? Thank you!
Topic: UI Frameworks SubTopic: SwiftUI
1
0
679
Dec ’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