How to test cloudkit containers

I'm trying to find a way to create and use a test cloudkit container in my swiftdata-backed app.

I want to test pre-filling the model container with localized content at first run.

To do this I created a test cloudkit container, and assigned it to my debug build profile in settings and capabilities.

I then conditionally reference the test container in my apps cloudkit manager, i.e.:

private let db: CKDatabase

       init() {
           #if DEBUG
           let container = CKContainer(identifier: "iCloud.com.team-name.myappname.testing-de") // Test CloudKit container
           #else
           let container = CKContainer(identifier: "iCloud.com.team-name.myappname") // Production CloudKit container
           #endif
           
           self.db = container.privateCloudDatabase
       }

But when I run my app in debug, content is still created in the primary/production container.

Am I missing something? Or is there a better, or documented, way to test cloudkit more robustly?

Answered by DTS Engineer in 830102022

SwiftData + CloudKit uses the container specified in cloudKitDatabase property of the model configuration. Assuming that the "content" you mentioned means the SwiftData data store, the CloudKit container you create, as shown in your code snippet, isn't relevant. The value of the cloudKitDatabase property is.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

SwiftData + CloudKit uses the container specified in cloudKitDatabase property of the model configuration. Assuming that the "content" you mentioned means the SwiftData data store, the CloudKit container you create, as shown in your code snippet, isn't relevant. The value of the cloudKitDatabase property is.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

How to test cloudkit containers
 
 
Q