Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to Toggle sync with NSPersistentCloudKitContainer
Did you get this to work? I have a similar need, that is, to offer iCloud storage and sync as a premium feature. I have CloudKit sync working but how do I switch it off? I want to disable CloudKit sync and only enable it when a customer pays for the premium version. I've tried setting the container's cloudKitContainerOptions property to nil but CloudKit sync still happens.Here's my Core Data stack:private lazy var persistentContainer: NSPersistentContainer = { let container = NSPersistentCloudKitContainer(name: modelName) let localDescription = NSPersistentStoreDescription(url: configurationsURL.appendingPathComponent(local.sqlite, isDirectory: false)) localDescription.configuration = Local let cloudDescription = NSPersistentStoreDescription(url: configurationsURL.appendingPathComponent(cloud.sqlite, isDirectory: false)) cloudDescription.configuration = Cloud cloudDescription.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: cloudKitContainerIdentifier) cloudDescrip
Sep ’19
Reply to Toggle sync with NSPersistentCloudKitContainer
What worked for me was setting cloudKitContainerOptions = nil before calling container.loadPersistentStores lazy var persistentContainer: NSPersistentContainer = { . . . if !UserDefaultsManager.shared.syncWithCloudKit { container.persistentStoreDescriptions.forEach { $0.cloudKitContainerOptions = nil } } container.loadPersistentStores( completionHandler: { (_, error) in ... } )This is a hack since this works only when persistentContainer is first initialized.Trying to do this after persistentContainer is initialized would require that I safely teardown and reinitialize the CoreDataStack. Reinitializing CoreDataStack creates a new managedObjectContext which then must be passed down the view hierarchy and to any services or managers that cache the managedObjectContext.There are many reasons to want to toggle or pause syncing with CloudKit, and since NSPersistentCloudKitContainer is privy to all the inner workings of syncing with CloudKit, NSPersistentCloudKitContainer should be the one to hand
Sep ’19
NSSecureUnarchiveFromData is now necessary for transformable attributes but does not work with Core Data CloudKit?
On iOS 13 for transformable attributes that have no custom Transformer class set this appears in the console:One or more models in this application are using transformable properties with transformer names that are either unset, or set to NSKeyedUnarchiveFromDataTransformerName. Please switch to using NSSecureUnarchiveFromData or a subclass of NSSecureUnarchiveFromDataTransformer instead. At some point, Core Data will default to using NSSecureUnarchiveFromData when nil is specified, and transformable properties containing classes that do not support NSSecureCoding will become unreadable.This message appears on devices, in the simulator on High Sierra it even leads to a crash.However, setting the transformer class to NSSecureUnarchiveFromDataTransformer when using CoreData CloudKit, this crashes and leads to Core Data not being initialized.Disabling CloudKit, e.g. setting the .cloudKitContainerOptions on the store description to nil fixes this crash.It seems CoreData CloudKit does not support NSSecureCoding tr
11
0
15k
Sep ’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
Core Data + CloudKit > how to incorporate existing app data into new NSPersistentCloudKitContainer
My experience implementing Core Data + CloudKit has frankly been relatively easy and I feel very positive about the new NSPersistentCloudKitContainer.Introduction and ThanksHonestly, I approached the new implementation of Core Data + CloudKit with some trepidation.My fears and anxiety were unfounded and I quickly learned just how (unsettlingly) easy it is to implement a CloudKit backed persistent store using NSPersistentCloudKitContainer.The new Core Data documentation is the best I've read by Apple for many years, so a huge and sincere thank you to the Core Data team.A couple of good posts on SO and a good blog by Andrew Bancroft helped close out my preliminary education... https://www.andrewcbancroft.com/blog/ios-development/data-persistence/getting-started-with-nspersistentcloudkitcontainer/The sample app provided by Apple (per WWDC session 202: Using Core Data with CloudKit) is madness for a beginner, however I really appreciate the effort that has gone into demonstrating SO MANY capabilities of
Topic: UI Frameworks SubTopic: UIKit Tags:
4
0
2.1k
Oct ’19
Force a NSPersistentCloudKitContainer sync
I have a SwiftUI app sitting on top of a CoreData + CloudKit stack. If I have the app running on multiple devices, a change on one device will not always be reflected on the others. However, restarting the app on the other device will pick up the change. For example:Device A and Device B both have the app running. Device B has it in the background.Device A changes Record 1. Device B returns to the foreground, but does not see the change to Record 1Kill the app on Device B, relaunch, and it sees the changeIt seems that the cloudkit process isn't always getting change notifications from iCloud (note that this happens on actual devices, not just the sim). If we could tell the container Hey, I just retuned to the foreground, maybe check to see if anything has changed?, that would, I think, fix the problem. I can't tear down my CoreData stack without rebuilding the entire app (since the main thread context is pushed down into SwiftUI).Is there a way to force this update?Thanks!Ben
4
0
4.7k
Nov ’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
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 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
Many-to-one relationship can't be unlinked
I am using NSPersistentCloudKitContainer, and have a many-to-one optional relationship, let say many item to one project.This relationship is optional, so I can do this ->item.project = nilwhen the user decided that this item does not belongs to any project.This code is fine in Core Data, and the inverse relationships are updated accordingly.However, once this gets synced to CloudKit, and come back down, the project relationship will be restored. Setting the project to other entities are fine, it just cannot be set to nil.Playing with the CloudKit dashboard, I realized that the schema that is created have a CD_Project as String. If I create a new item without any project, there's no such field, however, once I assign a project to an item, the field is set, and there is no way to unset this field, even from the CloudKit Dashboard. I naively tried to clear out the string in cloudkit dashboard but it crashes my app when the sync happens.Is this a bug that will be fixed? The issue is also posted by an
3
0
1.4k
Jan ’20
NSPersistentCloudKitContainer with Mac Catalyst
Hello,I ported the WWDC 2019 NSPersistentCloudKitContainer demo project to Mac Catalyst and it keeps on crashing everytime I run (within a minute or so of the app running). I'm getting the same BAD EXC INSTRUCTION on my Mac Catalyst app as well (which uses NSPersistentCloudKitContainer). Both projects run just fine on iPad and iPhone.Anybody experiencing the same issue? Any help would be appreciated.
6
0
2k
Jan ’20
NSPersistentCloudKitContainer CoreData & CloudKit Sync Crash
I am using the new iOS 13 NSPersistentCloudKitContainer for Syncing CoreData with iCloud.For large size binary data i am using Allow External Storage in Core Data Model.• I successfully added 200MB sized video on one device.• It got synced to iCloud successfully.• On the other device, when i am opening the App, it is receiving the CloudKit record, but somehow not able to work properly.There is no programming error from my end. I have made sure that in CoreData Model Allow External Storage is selected. Looks like it has something to do with how NSPersistentCloudKitContainer imports the large binary data.Errorerror: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x2805386c0> , *** NSAllocateMemoryPages(227428466) failed with userInfo of (null)CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x2805386c0> , *** NSAllocateMemoryPages(227428466) failed with userInfo of (null)2020-01-18 20:52:24
2
0
1.8k
Jan ’20
How to add Persistent History Tracking in already existing NSPersistentContainer
As I said in the title I have a core data container created in a custom class static var context: NSManagedObjectContext { let context = persistentContainer.viewContext context.automaticallyMergesChangesFromParent = true return context } // MARK: - Core Data stack static var persistentContainer: NSPersistentCloudKitContainer = { /* The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail. */ let container = PersistentContainer(name: App) container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { print(Unresolved error (error), (error.userInfo)) } }) let description = container.persistentStoreDescriptions.first description?.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) container.persistentStoreDescriptions = [desc
0
0
665
Jan ’20