Just in time schema in Cloudkit

445 views Asked by At

I want to use private database of cloudkit for my app, so for designing i was looking for something which would easily map my model classes to cloudkit without any extra efforts.

so i came across something interesting in the apple document where it is written,

During development, it’s easy to create a schema using CloudKit APIs. When you save record objects to a database, the associated record types and their fields are automatically created for you. This feature is called just-in-time schema and is available only when you use the development environment which is not accessible by apps sold on the store. For example, during development you can populate a CloudKit database with test records stored in a property list.

But i am not able to exactly understand the concept of the same or not able to find any reliable tutorial where this has been achieved.

1

There are 1 answers

3
Thunk On BEST ANSWER

In the development environment, you have two options for defining the DB schema. First, you can use the web portal and manually create new record types (adding field types as you go). Or, you can use the "just in time" route, meaning that you simply create new records in your code, add the desired fields and then save the record. In the development environment, that will automatically add the record type to the schema and save the data you provided in the new record.

That doesn't work in the production environment, though. You can't create new schema in the prod environment. The web portal will not allow you to manually create new record types. If you try to create a new record (or add new fields to an existing record) and save it in the prod environment, you'll get an error.

The only way to add a new record type (or add a new field to an existing record type) in the prod environment is to first create the change you want in the dev environment, then publish the changes from the dev environment to the prod environment.

In short, the dev environment schema is malleable and can be modified simply by creating new records and saving them. The prod environment schema is fixed, and can only be changed by modifying the dev env and then publishing the changes to prod.