I have a CoreData model with two entities, 'User' and 'Player', that both use 'Person' as their 'Parent Entity'. While the App appears to work correctly in the simulator, including with CloudKit via NSPersistentCloudKitContainer, I get a crash in Xcode Previews: libswiftCore.dylib [ AGScoringModel/Persistence.swift:183: Fatal error: #init(inMemory:): Failed to load persistent stores:Error Domain=NSCocoaErrorDomain Code=134110 An error occurred during persistent store migration. UserInfo={sourceURL=file:///Users/ebg/Library/Developer/.../CoreDataStores/private/database.sqlite, reason=Cannot migrate store in-place: Cannot merge multiple root entity source tables into one destination entity root table, destinationURL=file:///Users/ebg/Library/Developer/.../CoreDataStores/private/database.sqlite, NSUnderlyingError=0x600000ce02a0 {Error Domain=NSCocoaErrorDomain Code=134110 An error occurred during persistent store migration. UserInfo={message=Cannot merge multiple root entity source tables into one desti
Search results for
NSPersistentCloudKitContainer
589 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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
Operational transforms that model scalar values are typically implemented by collections of contributions (the operations). For example a vector or array of integers that represent the value. The implementations are necessarily aligned with application requirements like language, technology stack, supported distributed systems primitives etc. With NSPersistentCloudKitContainer such a counter is trivially implemented using a one-to-many or many-to-many relationship that joins the transformations to the root entity. If you have specific questions about that we are happy to help, but will require a little more context like your model and desired contribution structure.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
I have v3 models in coredata (model: Event, Lecture), and make new model in v4 with swiftdata but model name, property is different (model: EventModel, LectureModel). For migration, I add V3Schema, V4Schema and MigrationPlan. enum V4Schema: VersionedSchema { static var models: [any PersistentModel.Type] = [LectureModel.self, EventModel.self ] static var versionIdentifier = Schema.Version(4, 0, 0) } enum V3Schema: VersionedSchema { static var models: [any PersistentModel.Type] = [Event.self, Lecture.self] static var versionIdentifier = Schema.Version(3, 5, 2) } enum ModelMigrationPlan: SchemaMigrationPlan { static var schemas: [any VersionedSchema.Type] = [V3Schema.self, V4Schema.self] static var stages: [MigrationStage] = [migrateV3ToV4] } extension ModelMigrationPlan { static let migrateV3ToV4 = MigrationStage.custom(fromVersion: V3Schema.self, toVersion: V4Schema.self, willMigrate: willMigrate, didMigrate: { _ in Log.debug(message: Migration Complete) }) } private func willMigrate(context: ModelContext) thr
When there's a crash in WidgetKit, it often goes unnoticed by developers and users because there's no clear indication within the widget itself. In contrast, a crash in the main app is more apparent because it causes the app to close suddenly. One theory, as discussed in this https://developer.apple.com/forums/thread/668649, is that the main app and the widget are attempting to perform a migration simultaneously. However, I'm skeptical of this theory because our last CoreData migration began last year. Therefore, it's surprising to see a high number of crashes after a year. Here's where fatal error occurs. It is a pretty standard CoreData stack used in widget. private static func setupNSPersistentContainer() -> NSPersistentContainer { precondition(Thread.isMainThread) let container = NSPersistentCloudKitContainer(name: xxx, managedObjectModel: NSManagedObjectModel.xxx) // Integrate AppGroup with CoreData. If we are assigning a new store description to CoreData, it is important // to finish all sto
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
I work on a MacOS app (which has a companion iOS app) that uses Core Data with NSPersistentCloudKitContainer. The app also supports widgets and hence there is a need to migrate the persistent store within the core data stack using replacePersistentStore( at:.... During development I recently created a new model version and added a new entity, replaced some attributes etc... Working on the iOS app is fine because deleting the app clears all the data allowing me to work with a clean slate. On MacOS, I initially thought that I could simply navigate to the app group file location, delete the .sqlite file, along with the sqlite-shm and sqlite-wal. I also went and deleted the CloudKit related files. I did all of this out of pure ignorance - my expectation was that it would give me a clean slate, but it did not. This instead gave me some unpredictable behaviour, but the app was always in a bad state. the issues I saw were; • migration failure, • sqlite errors highlighting no such column: t0 - where all the
Hello, I'm running into an odd error. I'm trying to add a composite attribute called period to a Core Data Entity named Report, but I'm getting a compile-time error that points to my xcdatamodel file: Report.period cannot use an attribute type of Composite. In my model configuration I have Used with CloudKit box checked. If I uncheck this box, the error goes away and everything builds fine. But the documentation for NSCompositeAttributeDescription says: You may use composite attributes anywhere you use standard attributes, including lightweight migrations and CloudKit, through NSPersistentCloudKitContainer. So it seems like I should be able to use composite attributes in Core Data with CloudKit syncing enabled. What am I missing here? Is this a bug, or am I doing something wrong?
I use NSPersistentCloudKitContainer to fetch/sync data across multiple devices with the same iCloud account. /// ... container = NSPersistentCloudKitContainer(name: containerName) let description = container.persistentStoreDescriptions.first description?.setOption( true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) description?.setOption( true as NSNumber, forKey: NSPersistentHistoryTrackingKey) let viewContext = container.viewContext viewContext.automaticallyMergesChangesFromParent = true viewContext.mergePolicy = NSMergePolicy.mergeByPropertyObjectTrump NotificationCenter.default.addObserver( forName: .NSPersistentStoreRemoteChange, object: container.persistentStoreCoordinator, queue: .main ) { _ in Task { @MainActor [weak self] in // fetch new data and update widgets with it // ... viewContext.fetch ... // WidgetCenter.shared.reloadAllTimelines() } } } /// ... Everything works fine when my app in the foreground. How can I achieve the same when my app is clos
I am working on an interactive widget and merging changes provided by a user over it with the app. I store my data, using Core Data. However, I noticed an issue with sync between other user's devices after that person made a change over the widget (in my case, it is completing a task). Here is my schema: Main app: it looks for relevant transactions (https://developer.apple.com/documentation/coredata/consuming_relevant_store_changes). When it found that one, the app merges changes: if transaction.author == widget { if let userInfo = transaction.objectIDNotification().userInfo { NSManagedObjectContext.mergeChanges(fromRemoteContextSave: userInfo, into: [taskContext]) } } Widget: If the user clicks on the checkbox in order to complete a task, using an AppIntent class, app creates an identical NSPersistentCloudKitContainer and completes the task. However, in that case, the NSPersistentCloudKitContainer of the widget does not look for changes. That works correctly. However, only in a local enviro
I’m seeing the same error on both Xcode 15.0 and Xcode 15.1 Beta. For me, I think this issue stemmed from NSPersistentCloudKitContainerOptions. I’m using NSPersistentCloudKitContainer in my app. If I set NSPersistentStoreDescription.cloudKitContainerOptions to nil, this error would go away. Of course my app can’t sync via CloudKit if I do that. Another issue may or may not related to this warning: ever since I built my app on Xcode 15, I’ve seen excessive disk read on the sqlite file of CoreData on launch. The amount of disk read can be as much as twice the size of the sql file, basically making the app impossible to use for some users with large data set. But if cloudKitContainerOptions is nil, this excessive disk read would disappear. Last issue may or may not related to this warning: the size of CoreData sqlite file in my app is 130 MB. But in iPhone Settings → [User Name] → iCloud → Manage Account Storage, it says my app takes up a whopping 2.7 GB of space. No matter how the calculation is done,
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
What does a sysdiagnose from the watch tell you about your process' activity? i.e. Is it receiving push notifications? Are NSPersistentCloudKitContainer's activities being run? Reviewing this WWDC session may be helpful for interpreting the logs: https://developer.apple.com/videos/play/wwdc2022/10119/
Topic:
App & System Services
SubTopic:
Core OS
Tags:
One root cause that we have identified for this issue is removing a many-to-many relationship from your model. This is supposed to be a supported migration, so we are collecting feedback reports to track against that as a bug. If you would like to be notified of a fix for that share your feedback number here and we can relate them together. As a workaround you can simply add the relationship back. Or, attempt a more detailed / invasive solution described below. Our schema is public and described here: https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/reading_cloudkit_records_for_core_data Your container will contain CDMR records that identify the offending relationship. The fields CD_entityNames and CD_relationships can be used to tell which relationship a record represents. One (or more, depending on how many relationships you removed) of those records may be causing this issue. You can choose to: Add the missing relationship back to your model Delete the offending
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
I've encountered a significant sync issue with watchOS 10 RC on every device combination I've tested, running both iOS 17 and watchOS 10. I'm curious if others have noticed a similar problem. Context: Standalone watchOS app developed in SwiftUI with a companion iOS app. Both apps use NSPersistentCloudKitContainer for bi-directional CloudKit CoreData Sync between the iOS app and watch. Previously, this sync mechanism was near instant in the foreground and took max 1-2 minutes in the background NSPersistentCloudKitContainer has been reliable since the app was first developed in the watchOS 6/iOS 13 era. Issue: In watchOS 10 RC, sync can take hours--and doesn't even occur when the app is in the foreground. Sync only reliably happens when the watch is placed on the charger, seemingly only if the charge is over 50%. Once taken off the charger, the watch will continue push and receive CoreData changes briefly before becoming unresponsive to sync again. Additional Info: The problem persists even wh
CloudKit was working perfectly in iOS 16. However after updating to iOS 17 RC on my devices iCloud sync no longer works properly. The app has a package called CloudKitSyncMonitor which shows the sync status. Normally it would say Synced with iCloud but on iOS 17 it is either stuck in the Syncing or Sync not started state and the data doesn’t update. This mostly happens after a reinstall of the app. After some time it randomly decides to work until I uninstall the app. I’m really confused what could be the problem if it was working fine on iOS 16 but barely works properly on iOS 17? This is currently the code I have for the DataController: import SwiftUI import CoreData class DataController { var container: NSPersistentCloudKitContainer @AppStorage(wrappedValue:true,syncEnabled,store:UserDefaults(suiteName: group.com.ip18.SubManager)) var syncEnabled static let shared = DataController() init() { container = NSPersistentCloudKitContainer(name: Subscriptions) load(syncEnabled: syncEnabled) } fu
I have an existing iOS/watchOS app that uses a third-party database and WatchConnectivity. For various reasons I am migrating the app to use Core Data with CloudKit. I have everything working using NSPersistentCloudKitContainer. Sync between the iOS and watchOS app are working on my test devices when I start with an empty database. However, I need to import existing user's data when they first install this new version. Some users may have hundreds or thousands of records, but the total database size is under 1-2MB. Data migration/import is working on the iOS side, the Core Data entities are populated on first launch and uploaded to CloudKit (I see in the debug logs that a NSPersistentCloudKitContainer.Event export ends successfully). The problem is launching the watchOS app does not sync the data from CloudKit. I see a import started event but never see it end. I never see any Core Data entities appear on watchOS even after waiting several minutes and re-opening the Watch app multiple times. New enti