Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to Help with 2 way relationships with classes (SwiftData / cloudkit)
The error message you provided, “container not found errors“, doesn't seem to indicate anything related to your data model. If you can provide full description of the error, and also how you trigger the error, I may be able to comment. SwiftData's CloudKit integration is based on NSPersistentCloudKitContainer. You can also follow the following technotes to understand and debug any synchronization issue: TN3163: Understanding the synchronization of NSPersistentCloudKitContainer. TN3164: Debugging the synchronization of NSPersistentCloudKitContainer. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Sep ’24
Reply to SwiftData & CloudKit: getting info about current updates
SwiftData + CloudKit integration is based NSPersistentCloudKitContainer as of today, and so you can observe the synchronization events using eventChangedNotification with the following steps: Observe the eventChangedNotification notification. In your notification handler, use eventNotificationUserInfoKeyto retrieve the the event from notification.userInfo. Look into the event type, startDate, and endDate to understand the state of the event. For a runnable sample, please see Sharing Core Data objects between iCloud users. It is a Core Data sample, but the way to observe eventChangedNotification can be applied to SwiftData. Note that eventChangedNotification tells you the state of an individual export or import event, and not that the whole Core Data store is synchronized with the CloudKit server (or not), because there may have new changes happening on the CloudKit server while the event is being handled. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Sep ’24
Strange behavior with 100k+ records in NSPersistentCloudKitContainer
I have been using the basic NSPersistentContainer with 100k+ records for a while now with no issues. The database size can fluctuate a bit but on average it takes up about 22mb on device. When I switch the container to NSPersistentCloudKitContainer, I see a massive increase in size to ~150mb initially. As the sync engine uploads records to iCloud it has ballooned to over 600mb on device. On top of that, the user's iCloud usage in settings reports that it takes up 1.7gb in the cloud. I understand new tables are added and history tracking is enabled but the size increase seems a bit drastic. I'm not sure how we got from 22mb to 1.7gb with the exact same data. A few other things that are important to note: I import all the 100k+ records at once when testing the different containers. At the time of the initial import there is only 1 relation (an import group record) that all the records are attached to. I save the background context only once after all the records and the import group have been made and
3
0
703
Sep ’24
Reply to CloudKit: Handling CKError.partialFailure with pcs_data errors
_pcs_data is tied to the iCloud account (Apple ID), and is needed when an app accesses a CloudKit private database. When the device is logged out and then logged in with a new iCloud account, NSPersistentCloudKitContainer deletes the data owned by the original account. Unless you do something interesting that allows one account to access the database owned by the other, you don't need to worry about _pcs_data. The BAD_REQUEST error isn't quite concerning to me because NSPersistentCloudKitContainer takes care the requests and may retry them if needed. Worth mentioning though, CloudKit has some limits, as discussed in Avoid hitting a CloudKit limit. You might want to confirm that your app doesn't hit any of them. QUOTA_EXCEEDED is what I would concerned. It is related to the iCloud storage quota of the current logged in account. If that account did have plenty of un-used storage, as you had mentioned, it can be something on the system side went wrong – Either the device showed a wrong un-used
Aug ’24
CloudKit: Handling CKError.partialFailure with pcs_data errors
My iOS app uses Core Data for local data management and NSPersistentCloudKitContainer to sync data with user’s private iCloud storage. The app has been functioning correctly for several years, but recently, some users have started encountering a CKError.partialFailure error when the app attempts to export data to iCloud. Due to the critical nature of export errors, several features in the app have been disabled to prevent potential data duplication. Core Data Setup: lazy var container: NSPersistentContainer = { let container: NSPersistentContainer if storeType == .inMemory { // Used by unit tests container = NSPersistentContainer(name: models) container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: /dev/null) } else { container = NSPersistentCloudKitContainer(name: models) } container.loadPersistentStores { [weak self] _, error in if let error = error { self?.logger.error(Failed to load persistent store: (error)) fatalError() } } return container }() lazy var context: NSManag
1
0
689
Aug ’24
Reply to Swift Data and CloudKit
The issue you described can be that: SwiftData + CloudKit doesn't import the change from the CloudKit server. SwiftData + CloudKit does import the change, but Query doesn't update the data. I believe these were discussed in the following posts, respectively: CoreData + CloudKit synchronization is very unstable & unreliable Swiftdata using an existing CloudKit container, how to listen to the NSPersistentCloudKitContainer's NSPersistentStoreRemoteChange event Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’24
Reply to iPad os 18.1 iCloud error
For folks to be able to help, you might consider providing more context about your issue, like what Apple APIs you are using, how your app uses the APIs, how you trigger the issue, what the details of the error are. The log shows Core Data got involved. Assuming you are using Core Data + CloudKit, here are the technical resources that I believe can help debug the issue: TN3162: Understanding CloudKit throttles TN3163: Understanding the synchronization of NSPersistentCloudKitContainer TN3164: Debugging the synchronization of NSPersistentCloudKitContainer Sharing Core Data objects between iCloud users Best, —— Ziqiao Chen  Worldwide Developer Relations.
Aug ’24
Swiftdata using an existing CloudKit container, how to listen to the NSPersistentCloudKitContainer's NSPersistentStoreRemoteChange event
My app uses SwiftData and CloudKit to store and synchronize data. This works nice. in some scenarios, I need to listen to NSPersistentStoreRemoteChange event to deduplicate data. In SwiftData, how do I get the persistentStoreCoordinator of the corresponding SwiftData ModelContainer? Or are there other APIs to achieve the same purpose? There is no relevant content in the developer documentation. In addition, in wwdc 24, there is a new API to track history (https://developer.apple.com/cn/videos/play/wwdc2024/10075/). But there is no mention of how to listen to remote data change events either.
1
0
910
Aug ’24
Reply to Managing Duplicate Objects in Core Data (or SwiftData) with CloudKit Sync When Devices were Offline during object creation
Given this constraint, I believe there could be a more elegant sync approach than the Create duplicates in CloudKit and delete one method if only it would be possible for me to set recordName as I wish. There isn't unfortunately. This topic is discussed in Remove duplicate data. SwiftData with CloudKit Sync is based on NSPersistentCloudKitContainer, so the discussion applies to SwiftData as well. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Aug ’24
CoreData sharing/collaboration feature is broken
On top of unstable CloudKit sync, we've got also extremely unstable sharing/collaboration functionality. I mean, it's quite impressive how easy it is to enable sharing, but this feature should not be released at this point. It feels like using software in the alpha version. Let's take NSPersistentCloudKitContainer.share(_:to:) (https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer/3746834-share), the documentation says: Sharing fails if any of the following conditions apply: Any objects in managedObjects, or those the traversal finds, belong to > an existing share record. However, it's wrong... if you pass any object from the existing share, it will return the same share... It never fails in this case. Things are getting even weirder if you experiment a little bit with shares. So let's assume you share a couple of objects: persistentContainer.share([A, B, C, D], to: nil) Now you stop sharing those via UICloudSharingController and you want to share again but just C. So yo
1
0
669
Aug ’24
Reply to CoreData + CloudKit synchronization is very unstable & unreliable
CloudKit sync is very unstable. Sometimes it just stops syncing for no reason, other times it works almost instantly. When CoreData + CloudKit stops syncing, it can be that the system intentionally throttles the synchronization to balance the use of system resources and achieve the best overall user experience on the devices. To determine if that is the case and understand how the system works, you might want to read through the following technotes: TN3162: Understanding CloudKit throttles TN3163: Understanding the synchronization of NSPersistentCloudKitContainer TN3164: Debugging the synchronization of NSPersistentCloudKitContainer I also created a ticket: #FB14531806. Thanks for filing the feedback report. To investigate the issue, we would need to gather more information. If you don't mind, please follow the Provide actionable feedback section to gather the appropriate information and use it to update your feedback report. That would be a great help for the team's investigation. Best, ——
Aug ’24
Core Data Records Not Syncing with CloudKit Dashboard
Hello everyone, I'm currently working on an iOS app using SwiftUI and Core Data, integrating CloudKit for data synchronization. I've set up my Core Data stack with NSPersistentCloudKitContainer, and everything appears to be working correctly locally. However, I'm not seeing any records appearing in the CloudKit Dashboard. This issue started occurring after transferring the Apple Developer account ownership and changing the CloudKit container. Here's a summary of my setup and what I've tried so far: Setup PersistenceController.swift import SwiftUI import Foundation import CoreData import CloudKit class PersistenceController { static let shared = PersistenceController() let container: NSPersistentCloudKitContainer init() { container = NSPersistentCloudKitContainer(name: Model) guard let description = container.persistentStoreDescriptions.first else { fatalError(No Descriptions found) } description.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: iCl
1
0
1.2k
Jul ’24
CloudKit is not accessible from iOS extension targets
Hi! I'm using CoreData + CloudKit. It works well both on macOS and iOS, however, I can't make it work with extensions (share, action, keyboard). I get Invalid bundle ID for container error: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _recoverFromPartialError:forStore:inMonitor:](2812): : Error recovery failed because the following fatal errors were found: { = ; } I checked everything 10x: profiles, bundle ids, entitlements, etc. I even removed all local provisioning profiles and recreated them, I also tried setting different CloudKit container, but nothing helps. I tested it on a real device. My setup: main app bundle id: com.org.App.dev keyboard bundle id: com.org.App.dev.App-Keyboard action extension bundle id: com.org.App.dev.Action-Extension CloudKit container id: iCloud.com.org.app.dev I keep the CoreData database in the app group container, but I also tried locally and it doesn't really matter. This is how I setup my CoreData: self.persistentContainer = NSPersistentCloudKitContainer
3
0
787
Jul ’24
Reply to SwiftData via CloudKit Only Syncing Upon Relaunch
There is an eventChangedNotification on NSPersistentCloudKitcontainer. You can add a notification/listener to your view/Observable class and re-fetch data like so: import CoreData import SwiftData import CloudKit @Observable class ListViewModel { var cloudkitNotificationPublisher = NotificationCenter.default.publisher(for: NSPersistentCloudKitContainer.eventChangedNotification) func handleCloudkitNotification(_ notification: NotificationCenter.Publisher.Output) { if let userInfo = notification.userInfo, let event = userInfo[NSPersistentCloudKitContainer.eventNotificationUserInfoKey] as? NSPersistentCloudKitContainer.Event { if event.type == .import { // fetch entities/models here } } } } And then in your view, you can attach an .onReceive(_:) modifier to your view, passing in the publisher var body: some View { VStack { // my list here } .onReceive(listViewModel.cloudkitNotificationPublisher) { publisher in listViewModel.handleCloudkitNotification(publisher) } } More information can be found here: ht
Jul ’24
Core Data crashes when attempting to establish relationship to an entity with derived attribute in the background
I have recently moved some of my data save operations from the view context to background contexts. Since the switch, some (but not all) of my users are reporting that the background save operations crash 100% of the time. After researching, I have narrowed it down to the fact that these save operations involve establishing a relationship to an entity with a derived attribute. An example is shown below: try await CoreDataStack.shared.performBackgroundTask { context in var transaction = Transaction(context: context) transaction.amount = NSDecimalNumber(decimal: 0) transaction.id = UUID() let account = Account.account(withName: Default, in: context) transaction.account = account try context.save() } // <= Crashes! In the above example, each Transaction has a to-one relationship to an Account, and the latter has a to-many relationship the the former. Account has a derived attribute called balance that is calculated using the expression sum:(transactionItems.amount). The would then crash when the performBackgr
3
0
1.1k
Jul ’24