Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Getting errors when trying to connect to CloudKit using NSPersistentCloudKitContainer
I am trying to build a very basic app using Core Data and CloudKit. I am logged into my CloudKit account on my Mac, and I followed the instructions to run the sample project that Apple provided on their website.Using the sample project as a guide, I tried to build a simpler app using the instructions provided here.However, after building trying to run my sample project, I get the following error stack trace in my console:CoreData: debug: CoreData+CloudKit: -[PFCloudKitOptionsValidator validateOptions:andStoreOptions:error:](35): Validating options: <NSCloudKitMirroringDelegateOptions: 0x60000097f960> containerIdentifier:iCloud.com.cybermedia.CloudKitTest1 initializeSchema:YES ckAssetThresholdBytes:<null> operationMemoryThresholdBytes:<null> useEncryptedStorage:NO automaticallyDownloadFileBackedFutures:NO automaticallyScheduleImportAndExportOperations:YES skipCloudKitSetup:NO preserveLegacyRecordMetadataBehavior:NO useDaemon:YES apsConnectionMachServiceName:<null> containerProvider:<
5
0
7.4k
Jul ’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 CloudKit + SwiftData
In the CloudKit environment, duplicates can indeed happen if multiple peers can create the same data. We discuss this topic in Remove duplicate data. (As of today, SwiftData + CloudKit integration uses NSPersistentCloudKitContainer, and so the content applies.) Regarding CloudKit public database, yeah, it fits the use case where any user can generate data and all users can read the data. However, SwiftData + CloudKit public database integration is not supported today. You probably need to stick with NSPersistentCloudKitContainer if to use CloudKit public database. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jun ’24
NSPersistentCloudKitContainer: Migration failed based on alphabetical order
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.
4
0
1k
Jun ’20
NSPersistentCloudKitContainer: Migrating multiple devices with data changes in between
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.
9
0
2k
Jun ’20
Reply to Questions About Updating Older Core Data / iCloud App to Core Data / CloudKit
Once I have the path, I plan to do this.lazy var persistentContainer: NSPersistentCloudKitContainer = { let container = NSPersistentCloudKitContainer(name: “MyAppName”) // Create a store description for a CloudKit-backed local store let cloudStoreLocation = URL(fileURLWithPath: Original or Ubiquity Path) let cloudStoreDescription = NSPersistentStoreDescription(url: cloudStoreLocation) cloudStoreDescription.configuration = Cloud // Set the container options on the cloud store cloudStoreDescription.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions( containerIdentifier: com.my.container) // Update the container's list of store descriptions container.persistentStoreDescriptions = [ cloudStoreDescription, ] // Load store container.loadPersistentStores { storeDescription, error in guard error == nil else { fatalError(Could not load persistent stores. (error!)) } } return container}()
Jun ’19
Reply to PersistenceController and CloudKit
struct PersistenceController { static let shared = PersistenceController() let container: NSPersistentCloudKitContainer init() { container = NSPersistentCloudKitContainer(name: MJ) guard let fileContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: group.com.Jad.MJ)?.appendingPathComponent(MJ.sqlite) else { fatalError(Shared file container could not be created.) } let storeDescription = NSPersistentStoreDescription(url: fileContainer) storeDescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) storeDescription.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) storeDescription.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: YOUR containerIdentifier) container.persistentStoreDescriptions = [storeDescription] container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { fatalError(Unresolved error (error), (er
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’21