Cloudkit - Coredata and multiples database

Today, I'm working without cloudkit (all data are in a local Coredata), with one database on my Xcode project but with 2 containers on app.delegate :

  • one for a test environment : with storeURL  ---> test.sqlite
    
  • one for a production environment : with storeURL --> production.sqlite
    

Everything is ok, the test data, is really separate from production data.

Now, I try to use cloudkit functions : I change NSPersistentContainer to NSPersistentCloudKitContainer

it's working and I could use data on 2 iPads.

BUT if I switch the test to the prod, now the data from test environnement is duplicate on the production environnement.

what mistake am I making? How could I use my two storeURL with cloudkit coredata?

Thanx for your help.

Accepted Reply

You need to associate the test & prod with its own container id. Add them via Xcode iCloud capabilities containers list.

let testContainerID = NSPersistentCloudKitContainerOptions(containerIdentifier:"your_bundle_id.test")
let prodContainerID = NSPersistentCloudKitContainerOptions(containerIdentifier:"your_bundle_id.prod")

Assign each container ID to the respective data store

Replies

You need to associate the test & prod with its own container id. Add them via Xcode iCloud capabilities containers list.

let testContainerID = NSPersistentCloudKitContainerOptions(containerIdentifier:"your_bundle_id.test")
let prodContainerID = NSPersistentCloudKitContainerOptions(containerIdentifier:"your_bundle_id.prod")

Assign each container ID to the respective data store

Thank you for your response...

It's working except that I loose my old container because when app start, there is no data...I will try to copy old data on new container