I added a new Core Data model version, introducing a new entity. Based on the naming of the Entity I get different behaviour: A: If the entity is alphabetically ordered as last entity: Everything works fine. B: There entity is ordered before already existing entities: All records of these existing entities get a new CloudKit id. Resulting in duplicated data and broken relations. In some cases the seem-to-be new insert of these records causes the migration to fail. (Constraint unique violation, reason=constraint violation during attempted migration) My only workaround so far is to just give the entity a different name, to appear last in the list. __ Does anyone else experience this issues? I am not sure if my code could be able to trigger this kind of behaviour. I will try to reproduce it in an empty project, to file a bug report.
Search results for
NSPersistentCloudKitContainer
589 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
What is the expected / best strategy to migrate a synced Core Data model to a new version? The issue: A new app version with a new Core Data model introducing new attributes or entities. DeviceA installs the update and edits data with new values and creates new entities. DeviceB is still used and downloads these changes. The unknown attributes and entities are ignored, but the HistoryTracking gets updated. A few days later DeviceB gets the update. The missing attributes and entities are not downloaded, as the history is up to date. __ The issue exists with iOS 13, I hoped for iOS 14 to introduce a strategy. I tried with the first iOS 14 beta, but it is at least not handled automatically. From the visible API changes I don't see a way to handle this specifically. Not sure if the talks will reveal anything about it. Will apply for a lab session and would like to get as much input to prepare before that might take place.
I see some sessions about using NSPersistentCloudKitContainer with the public CloudKit database, and it now accepts a ‘databaseScope’ property - can this be used with shared CloudKit databases?
If you are trying to use an App Group container to share a database between your iOS app and an WatchKit extension, that won't work because the iOS app runs on iPhone and the WatchKit extension runs on the paired watch, and an app ground container can't be cross devices. You will have to synchronize the data across the devices with your own code. As Nick points out, you can try with NSPersistentCloudKitContainer, you can also use CloudKit directly to synchronize the data you need. WatchConnectivity is not recommended if you want your watch app to be standalone.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
NSPersistentCloudKitContainer does not yet support sharing, please consider filing a feedback request with details about your desired use case.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
AFAIK Watch apps do not naturally sync data back to the companion. This has to be done via one or more of these solutions, Keeping Your watchOS Content Up to Date - https://developer.apple.com/documentation/watchkit/keeping_your_watchos_content_up_to_date. The easiest way to do that would be NSPersistentCloudKitContainer, however WatchConnectivity - https://developer.apple.com/documentation/watchconnectivity may be a better fit depending on your needs.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
How can I check that an entity already exists remotely ? In theory you could write some CloudKit code to execute a CKQueryOperation that checks for your seed content. But that won't handle the race between a device exporting the data and another device launching the app and parsing the json file. You can also check if records exist in the local store using NSFetchRequest. However for the same reason that won't prevent you from inserting duplicate records on multiple devices if they haven't synced with the CloudKit server yet. There are a number of approaches to seeding your application store with content in a reliable way: Don't sync the seed content, instead use an un-synced store to hold the data from the JSON file and a synced store to hold user data Unique the seed content on each device as it is updated by NSPersistentCloudKitContainer Unfortunately NSPersistentCloudKitContainer does not support unique constraints yet, you can file a feedback request for that though.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
You can use the feedback assistant to file bugs against NSPersistentCloudKitContainer. Include the following: A sysdiagnose from all of the participating devices The persistent store files from all of the participating devices If your dataset is large, a detailed accounting of the affected records and the mutations made to them from each device (as well as you recall, history tracking is the truth)
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
Using NSPersistentCloudKitContainer: I have a relation between Item --to-one--> Group. This works fine on device: I can set a Group for an Item and remove the Item from the Group again, everything is persisted locally. The Problem: Adding does work, but removing the Group never appears on a different device. As soon as the Item gets edited on the different device, the Group relation re-appears with the new changes (even if manually removed there as well). What I see in CloudKit dashboard: Group field on Item is of type String. A fresh Item record, never assigned to a Group, does not have the Group field. Removing the Group does not remove the Group field in CloudKit. As soon as it gets a Group field, I can’t get rid of it. Manually emptying the value causes to crash on download. Reproducible with the example project: The behaviour can easily be reproduced with the example project (https://developer.apple.com/documentation/coredata/synchronizing_a_local_store_to_the_cloud?language=objc). Just repla
You wrote: [objectID] certainly changes from run to runI'm not seeing that. It seems to be completely consistent. I was using `objectID.uriRepresentation()` to implement `Identifiable`, and the docs for `uriRepresentation` say it is archivable, which suggests to me that it doesn't change. (?) I'm using `NSPersistentCloudKitContainer`, if that matters.I think that what's getting me now is...ForEach(dataSource.fetchExercises(moc:moc)) { ex in NavigationLink(destination: ExerciseView(exercise: ex)) { ListItemView(exercise: ex) } }If that detail view (ExerciseView), changes the exercise in way that should _reorder_ the results of fetchExercises and the ForEach, then I make `dataSource` (which is an observable object) emit `objectWillChange`. As expected, SwiftUI re-calls `fetchExercises`. But sadly, it pops off the detail view (ExerciseView) and returns to this list view.I thought it should see that the exercise objects have the same IDs, so it would keep the ExerciseView pushed.I too am interested to se
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
Hello,I'm parsing objects from a JSON file and store them into my Core Data store.I'm using NSPersistentCloudKitContainer and when I'm running the app on a different device, it also parses the JSON file and adds objects to Core Data. That results in duplicate objects.How can I check that an entity already exists remotely ?
I'm experimenting with Core Data and CloudKit using the recommended `NSPersistentCloudKitContainer`. I'm kind of new to Core Data so maybe I'm doing something simple/stupid. I get an error when changing the object twice, quickly.I have a SwiftUI view of one of my managed objects, with button toggle the isActive property. If I tap it twice in a row, I get an error from `NSManagedObjectContext.save`. How do you prevent or recover from this kind of error?It seems to be a timing thing, because I'm having trouble duplicating it. private func toggleActiveState() { exercise.isActive = !exercise.isActive try! moc.save() // error }RobFatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=133020 Could not merge changes. UserInfo={conflictList=( NSMergeConflict (0x282fb15c0) for NSManagedObject (0x2819ca8a0) with objectID '0xb61bc172bb432131 <x-coredata://6C618B32-5866-4E35-93C9-3B7F3D221FE6/MyObject/p7>' with oldVersion = 4 and newVersion = 5 and old object snap
So I've been developing happily with CoreData+CloudKit for a while now, and really haven't run into any issues until this. I've migrated my model a couple of times, and it worked fine, but this was the first time I added a new entity to the model. If I run on a device (any device, iPhone, iPad, Mac via Catalyst), I get a migration error. Here's the entirety of my persistentContainer setup: public var persistentContainer: NSPersistentContainer = { let modelPath = Bundle(for: CoreDataStack.self).url(forResource: Progress, withExtension: momd)! let model = NSManagedObjectModel(contentsOf: modelPath)! let container = NSPersistentCloudKitContainer(name: Progress, managedObjectModel: model) container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { print(storeDescription) fatalError(Unresolved error (error), (error.userInfo)) } }) return container }()And here's the error I'm getting:Callstacks=true}}}CoreData: annotation: : Attempting recovery from e
I have moved my NSPersistentContainer in my app to an NSPersistentCloudKitContainer to sync data between devices (iPhone, iPad, and Apple Watch supported). Sync works just fine in test & production, but after a few days it will stop working and behave as if each device is using local storage. This continues to happen until I reinstall the app and it syncs again, but only for a short time until it goes back to using local storage again. Does anyone know of a way to debug this?
I would need to access CKRecords of my NSManagedObjects on iOS 13.4 and there seems to be a documented method in NSPersistentCloudKitContainer, but the compiler can't see it! How this can be?Compilation error:https://vesacdn.s3.eu-north-1.amazonaws.com/compilation+error.pngClass definition seen by xcode 11.4.1:https://vesacdn.s3.eu-north-1.amazonaws.com/NSPersistentCloudKitContainer.pngDocumented:https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer