Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to NSPersistentCloudKitContainer "migrate to a completely new store"?
So I believe I am overthinking it!lazy var persistentContainer: NSPersistentCloudKitContainer = { let container = NSPersistentCloudKitContainer(name: Model) let storeLocation = URL(fileURLWithPath: /path/to/cloud.store) let storeDescription = NSPersistentStoreDescription(url: storeLocation) //Set the container options cloudStoreDescription.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: com.myCompany.myApp2) // TODO: Migrate Core Data Store to new Model Version container.loadPersitentStores... ... }()This should be enough to handle the migration from Container 1 to 2, since the data is already stored in Core Data. Then instead of hooking up a persistent container to the old CloudKit container (which would probably throw errors due to mismatched Schema), we can use CloudKit to fetch and confirm all data has already transfered properly, fix missing data, and delete the recrods in Container 1.I decided not to Migrate Containers for this, instead Im using ver
Mar ’20
NSPersistentCloudKitContainer "migrate to a completely new store"?
I have a model that has already been pushed to production, and I would like to move an attribute to a new entity as a relationship.From This:extension Note { @NSManaged public var drawingData: Data? .... }To This: extension Note { @NSManaged public var drawing: Drawing? .... } extension Drawing { @NSManaged public var drawingData: Data? .... }According to the Apple Docs under the Update your Production Schema section, I will need to migrate to a new CloudKit Container, since we can't delete attributes on production CKRecords.What is the proper workflow to do this?I have come up with the following, but I believe it is wrong.lazy var oldPersistentContainer: NSPersistentCloudKitContainer = { let container = NSPersistentCloudKitContainer(name: Model) let storeLocation = URL(fileURLWithPath: /path/to/cloud.store) let storeDescription = NSPersistentStoreDescription(url: storeLocation) // Set the container options on the cloud store cloudStoreDescription.cloudKitContainerOptions = NSPersistentCloud
1
0
1.5k
Mar ’20
CKFetchRecordZoneChangesOperation breaks NSPersistentCloudKitContainer when called inside AppDelegate?
I'm trying to call CKFetchRecordZoneChangesOperation to get the latest changes from the shared database.But when I run that operation from inside didFinishLaunchingWithOptions, NSPersistentCloudKitContainer will break. It will save to coredata, but it will no longer sync to Cloudkit. It's as if it's paused. When I restart the app, the sync resumes.But if I call CKFetchRecordZoneChangesOperation later in the app lifecycle, say in viewDidLoad, everything works fine. Why is this?
1
0
647
Feb ’20
NSPersistentCloudKitContainer multiple stores
Hello,I'm working on refactoring an existing app to use the new NSPersistentCloudKitContainer.Our app is managing different Projects items which consist of a mix of structured data and files.Files are stored locally and only their path are stored in one core data store at the moment.Enabling NSPersistentCloudKitContainer did the job as now the db syncs between devices as expected.As we would like to segregate each project into its own CoreData store, my question is: Is it possible to leverage NSPersistentCloudKitContainer to sync multiple core data stores within the same app and have all of those stores synced?Can you point me to any documentation that demonstrate this use case?Thanks for the feedback.Best regardsSantiago
1
0
801
Jan ’20
Reply to CloudKit + Core Data General Questions (HIG)?
Oh cool, I guess cmd+s is post....2) I'm curious if there's a means to allow the user to choose the version of the data in CloudKit or the version of the data on Device. My data sort of adds up to an expected whole. If one record is added or deleted, then the sum of the records will be incorrect. To give the user a good experience, I'd like to give them the ability to pick a snapshot of two different versions of their entire data set.Can `NSPersistentCloudKitContainer` facilitate this in anyway?3) Is there a best practices guide or design pattern recommendations with recards to UX anywhere?
Feb ’20
CloudKit + Core Data General Questions (HIG)?
I've got a few quetsions about designing an acceptable user experience involving migrating from legacy Core Data store to a CloudKit+CoreData store.Given the user can have a legacy data store on all of their devices and only one of those sets of data will be considered supreme, I need a means to effectively merge all this data in a non-destructive way.1) Does NSPersistentCloudKitContainer provide a means of opting into or out of CLoudKit storage for the user? Is it fully reliant on the user going into settings and flipping the iCloud-Data switch? Or can I maintain a local app settings flag? Can I tell a NSPersistentCloudKitContainer to no longer sync during it's lifecycle? 2)
1
0
696
Feb ’20
Reply to NSSecureUnarchiveFromData is now necessary for transformable attributes but does not work with Core Data CloudKit?
I'm experiencing the same or similar problem.I suspect, but I am not certain, that it is a bug and I'll try to explain my reasons why... but first...My scenario:Xcode 11.3 project developing for iOS 13.x and beginning to implement NSPersistentCloudKitContainer.I have `Transformable` type attributes for two Entities in my data model (for some time now). Incidentally both these attributes are used to store an optional value for Measurement<UnitMass>, which I understand from my reseach, conforms to `Encodable` and is therefore able to just work with a Core Data attribute of type `Transformable`. Others have written more on the capabilities of the Foundation `Measurement` class, using more accurate language than me, in this and other forums, so I'll leave this part of my description short.As I am still in development with my Xcode project, I regularly switch between NSPersistentContainer and NSPersistentCloudKitContainer for testing purposes. This requires regularly resetting the development enviro
Feb ’20
Reply to NSBatchInsertRequest
HiI try to use the NSBatchInsertRequest. but the insertResult is nil, and my CoreData is emptyI use the viewContext of the NSPersistentCloudKitContainer.let container = NSPersistentCloudKitContainer(name: CoreDataPerformance) container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { fatalError(Unresolved error (error), (error.userInfo)) } }) try container.viewContext.setQueryGenerationFrom(.current) let moc = container.viewContext moc.automaticallyMergesChangesFromParent = true moc.perform { let insertRequest = NSBatchInsertRequest(entity: Client.entity(), objects: clients) let insertResult = try? moc.execute(insertRequest) as? NSBatchInsertRequest if let success = insertResult as? Bool { print(RESULT: (success)) } }This is the error I receive in the console.2020-02-04 18:30:25.800705+0200 CoreDataPerformance[62836:778869] [error] warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass 'CoreDataPerformance.Client' so +entity
Feb ’20
Reply to Force a NSPersistentCloudKitContainer sync
Have you set automaticallyMergesChangesFromParent = trueI choose to do this after I load my persistent container... lazy var persistentContainer: NSPersistentContainer = { let container = NSPersistentCloudKitContainer(name: persistentStoreName) container.viewContext.automaticallyMergesChangesFromParent = true container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { fatalError(Unresolved error (error), (error.userInfo)) } container.viewContext.automaticallyMergesChangesFromParent = true return container }()
Dec ’19
Reply to NSPersistentCloudKitContainer not syncing existing data
Nick, thanks for the input.Behaviours I've noticed...Scenario 1Existing Core Data app with existing records.Log in to the same Apple ID on different Simulators or Devices.Enable NSPersistentCloudKitContainer and include container.viewContext.automaticallyMergesChangesFromParent = trueOnly new records are synced to users CloudKit account and therefore across devices using the same Apple ID. Existing records remain only on the device on which they are created.Scenario 2Existing Core Data app with existing records.Log in to the same Apple ID on different Simulators or Devices.Enable NSPersistentCloudKitContainer and include container.viewContext.automaticallyMergesChangesFromParent = trueEnable NSPersistentHistoryTrackingKey... guard let containerStoreDescription = container.persistentStoreDescriptions.first else { fatalError((#function): Failed to retrieve a persistent store description.) } containerStoreDescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)ANY records
Dec ’19
Reply to Toggle sync with NSPersistentCloudKitContainer
I spoke to an Apple Engineer about this and they suggested the best way was to make your container return either an NSPersistentContainer or NSPersistentCloudKitContainer depending on whether you users have selected iCloud syncing internally in your app - you can use a UserDefaults bool to store this.This works because NSPersistentCloudKitContainer is a subclass of NSPersistentContainer.You will also need to set the NSPersistentHistoryTrackingKey to true on the vanillla container so changes are recorded should they switch iCloud back on. There doesn't appear to be any need to set any options manually on NSPersistentCloudKitContainer as they're enabled by default.I have a PersistenceService class which manages my MOC and in it, this is how I set up the container: static var iCloudSyncData = UserDefaults.standard.bool(forKey: iCloudSyncData) static var persistentContainer: NSPersistentContainer = { let container: NSPersistentContainer? if iCloudSyncData { container = NSPersistentCloudKitContainer
Nov ’19
How do you create a one to many relationship with Core Data Model for CloudKit?
I can't seem to figure out how to get a one-to-many relationship working with a NSPersistentCloudKitContainer. Has anyone been able to do this successfully? I see the relationship that is one-to-one on the other end, but not the relationship which is supposed to be many to many.I've been trying to use the information here https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/creating_a_core_data_model_for_cloudkit#3191035and am unsure if this is a limitation of CloudKit and CoreData, if the data is there and just not showing in the dashboard or any other option.I've put my code here on Github https://github.com/jknlsn/testcloudkit and would love any help or thoughts. I would also be very keen to hear of any better ways to be debugging and visualising this data I am trying to write apart from the CloudKit dashboard, I don't know yet how to retrieve and display the data with SwiftUI.
1
0
1.2k
Oct ’19
NSPersistentCloudKitContainer can't get record from NSManagedObjectId
I try to figure out if it's possible to share a users core data events in one app, to another user with CKShare and CKRecord.I got the device sync up and running and can see the changes, also CloudKit dashboard has published the changes to production.However, when I have my NSManagedObject that I got either local or from another device, I try to call the following:let myEvent: // NSManagedObject from core datalet container: NSPersistentCloudKitContainer = AppDelegate.shared.containerlet record = container.record(for myEvent.objectID // not working// record is always nilThe receord is always nil, why?And is is possible to later pass the CKRecord in a UICloudSharingController to share it to another user?
4
0
1.6k
Jun ’19