Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

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
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
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
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
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
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
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
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
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
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