Cloudkit 中的即时模式

Just in time schema in Cloudkit

我想为我的应用程序使用 cloudkit 的私有数据库,因此为了设计,我一直在寻找可以轻松地将我的模型 类 映射到 cloudkit 的东西,而无需任何额外的努力.

所以我在 apple document 那里看到了一些有趣的东西,

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.

但是我不能完全理解相同的概念,或者找不到任何可靠的教程来实现这一点。

在开发环境中,您有两种定义数据库架构的选项。首先,您可以使用门户网站并手动创建新的记录类型(随时添加字段类型)。或者,您可以使用 "just in time" 路由,这意味着您只需在代码中创建新记录,添加所需的字段,然后保存记录。在开发环境中,会自动将记录类型添加到架构中,并将您提供的数据保存在新记录中。

不过,这在生产环境中不起作用。您无法在生产环境中创建新架构。 Web 门户不允许您手动创建新的记录类型。如果您尝试创建新记录(或向现有记录添加新字段)并将其保存在 prod 环境中,您将收到错误消息。

在生产环境中添加新记录类型(或向现有记录类型添加新字段)的唯一方法是首先在开发环境中创建您想要的更改,然后从开发环境中发布更改环境到产品环境。

简而言之,开发环境架构具有可塑性,只需创建新记录并保存即可对其进行修改。 prod 环境模式是固定的,只能通过修改 dev env 然后将更改发布到 prod 来更改。