Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to MAJOR Core Data Issues with iOS 18 and sdk - Data Missing for many users?!
Is there a way to get the container from a device NOT having Xcode or Development tools if they can connect to a Mac? Not that I am aware of. Many of whom DO NOT use iCloud which is also weird. A few using iCloud but most are NOT. Any thoughts on why that might be? If the impacted users didn't use iCloud, you can rule out CloudKit, which will simplify the issue a bit. However, I still can't say anything for sure – Debugging a random data loss can be hard and my sitting here and guessing won't be helpful. To eventually figure it out, you might consider reaching out the impacted users to hopefully find more hints, or ideally, create a reproducible case. now it is almost as if a user has NSPersistentCloudKitContainer options set to nil and the data is deleted. Can you confirm or provide a link to documentation confirming? Setting the CloudKit option to nil does not delete the data in the existing Core Data store. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jan ’25
Reply to SwiftData & CloudKit: Deduplication Logic
SwiftData and CloudKit are two different frameworks, and so you are free to use both of them in your app. Note that CloudKit here means the CloudKit framework, not NSPersistentCloudKitContainer. As of today, when you configure SwiftData to use CloudKit, as mentioned in here, SwiftData uses NSPersistentCloudKitContainer underneath to sync the data, and so you won't want to create your own NSPersistentCloudKitContainer instance for the purpose. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jan ’25
Reply to CloudKit sync stopped working with error „You can't save and delete the same record"
Thanks for the reply! Firstly, correct, we're using CoreData + CloudKit and mirrored relationships means reflexive relationships (e.g., Article.similarArticles whereby both are of the type Article). Assuming that you are using Data + CloudKit, I am guessing that this can be triggered by your code and data. Regrettably, that doesn't seem to be the case, also given the Delete Rule is Nullify. Digging through our old messages, we found out that we had already reported this very same issue a couple of years ago with a similar data model but where no entity was ever deleted. At that time we filed feedback report 9118745 and we were told that this was likely a bug. it is worth filing a feedback report for the Core Data team Given this seems to be the very same issue, I’ve added the information of this post to our above ticket (and have provided the relevant system diagnose logs, data model, etc. there too). Does your Core Data model indeed has the reflexive relationship? If yes, has it been there for long time, or
Jan ’25
Reply to Why did NSPersistentCloudKitContainer added CKAsset fields for each String in Core Data
Adding a CKAsset field for a Core Data String attribute is as designed. It is because the size of a CloudKit record (not counting assets) is limited to 1MB, while a Core Data attribute has no size limit. What ChatGPT said is basically right – When the size of a Core Data String attribute exceeds a certain value, NSPersistentCloudKitContainer converts it to a CKAsset object in the data transformation process. Whether the value is about 1KB or not is not formally documented though. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jan ’25
Why did NSPersistentCloudKitContainer added CKAsset fields for each String in Core Data
Hi, I've been using Core Data + CloudKit via NSPersistentCloudKitContainer for several years now. Back then I just created my Core Data AND CloudKit fields by hand. Now the time has come for a little lightweight migration to a new Core Data model, let's say I just needed to add one String attribute. So I've done the Core Data local migration as usual, then added this to container code: try? persistentContainer.initializeCloudKitSchema(options: NSPersistentCloudKitContainerSchemaInitializationOptions()) Run. And everything worked great. but… Now I've noticed that CloudKit created new CKAsset fields for each String attribute that I had in Core Data (about 5 new CKAsset fields). Is this normal!? Why? ! Is it safe to deploy these changes to prod? ty. ChatGPT said: This field is used internally by CloudKit to handle large string values. If the string value is small enough, it is stored in the normal String field, but if it exceeds the size limit (about 1KB), the string is automatically stored as a CKAsset
1
0
835
Jan ’25
Reply to Recovering Customer's Data After iCloud Migration
@DTS Engineer We are not currently using any APIs specifically for iCloud account switches. Our app’s data is managed entirely through Core Data, backed by NSPersistentCloudKitContainer for synchronization with iCloud. When my colleague checked the CloudKit Console after logging into their iCloud account, they did not see the custom zone we use to store Core Data records. This absence has us concerned about whether the data is still recoverable. If the iCloud account is still active, should Core Data records managed via NSPersistentCloudKitContainer automatically sync back? Or does switching iCloud accounts result in the permanent deletion of associated Core Data records? Our plan is to recommend that the user logs back into their original iCloud account, ensures that iCloud is enabled for our app, and opens the app to allow time for the data to sync back. Is this the correct approach for recovering the data, or are there additional steps we should take? Any guidance would be greatly appreci
Jan ’25
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