"Core Data with CloudKit uses a specific record zone in the CloudKit private database, which is accessible only to the current user."
It's not possible to use CloudKit and CoreData with the CloudKit public database? Here is my scenario.
- I have an application with two core data stores.
- The first store should be synced with the public CloudKit database and NOT updated by the user.
- The second store should be synced with the private CloudKit database and updated by the user.
lazy var persistentContainer: NSPersistentCloudKitContainer = {
let container = NSPersistentCloudKitContainer(name: "MyAppName")
// Create a store description for the first store
let firstStoreLocation = URL(fileURLWithPath: "/path/to/first.store")
let firstStoreDescription = NSPersistentStoreDescription(url: firstStoreLocation)
firstStoreDescription.configuration = "First"
// Create a store descpription for the second store
let secondtoreLocation = URL(fileURLWithPath: "/path/to/second.store")
let secondStoreDescription = NSPersistentStoreDescription(url: secondtoreLocation)
secondStoreDescription.configuration = "Second"
// Set the container options on the first store
firstStoreDescription.cloudKitContainerOptions =
NSPersistentCloudKitContainerOptions(containerIdentifier: "com.my.container1")
// Set the container options on the second store
secondStoreDescription.cloudKitContainerOptions =
NSPersistentCloudKitContainerOptions(containerIdentifier: "com.my.container2")
// Update the container's list of store descriptions
container.persistentStoreDescriptions = [
firstStoreDescription,
secondStoreDescription
]
// Load both stores
container.loadPersistentStores { storeDescription, error in
guard error == nil else {
fatalError("Could not load persistent stores. \(error!)")
}
}
return container
}()
This code would setup sync with two stores and two different containers with private databases?
It would be great if you could use the same container but different databases.