Database not deploying to CloudKit

I am trying to port my application over to CloudKit. My app worked fine before, but then I made scheme of changes and am trying to deploy to a new container. For some reason, the database is not being created after I create the container through Xcode.

I think I have configured the app correctly and a container was created, but no records were deployed. My app current stores data locally on individual devices just fine but they don't sync with each other. That's why I would like to use CloudKit.

See screenshot from Xcode of where I have configured the container. I also have background notifications enabled. Also see screenshot from console where the container has been created, but no records have been.

Any suggestions would be greatly appreciated.

Thank you

Answered by DTS Engineer in 820441022

Is there a reason when I run the app, it doesn't build a schema automatically in the new container?

In the development environment, CloudKit automatically creates the schema only when you create the data, and it has always been the case.

When using Core Data + CloudKit, you typically need to call initializeCloudKitSchema(options:) to create the CloudKit schema that matches their Core Data model, or keep it up to date every time their model changes, as described in the mentioned sample code Readme.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

noticed this as well

Did you ever run your app and save some data to the CloudKit-backed Core Data store? NSPersistentCloudKitContainer only creates the custom zone when there is data.

Also, you need to initialize the CloudKit schema, if not yet. See Create the CloudKit schema for the more details.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

the link took me to an article about duplicate data. I thought the schema was created automatically from my model. it was for other apps I've developed. Do I have to do something special here?

Oh, sorry for the wrong link. Here is the right one: Create the CloudKit schema

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

I'm not deploying to production. I'm only using the development database. Is there a reason when I run the app, it doesn't build a schema automatically in the new container? It has before I'm not sure why it's not doing it now. I did reset the database environment if that broke something.

Is there a reason when I run the app, it doesn't build a schema automatically in the new container?

In the development environment, CloudKit automatically creates the schema only when you create the data, and it has always been the case.

When using Core Data + CloudKit, you typically need to call initializeCloudKitSchema(options:) to create the CloudKit schema that matches their Core Data model, or keep it up to date every time their model changes, as described in the mentioned sample code Readme.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

I figured it out. I had a parent-child relationship between meals and ratings.

class Meal: Identifiable { var id: UUID = UUID() var name: String = "" ... var ratings: [Rating]? = [] // made this optional ... }

@Model class Rating: Identifiable { var id: UUID = UUID() var value: Int = 0 var date: Date = Date() var meal: Meal? // added this ... }

without ratings being optional and a meal? attribute on ratings, the app couldn't create the schemer in cloud kit. It then went ahead and created the scheme as locally on the devices instead.

Once I made these changes to the data model, the app created the schema in cloudkit.

Otherwise it was creating them locally on the device and it looked like the app was working fine.

Thanks

Database not deploying to CloudKit
 
 
Q