Using CloudKit Dashboard to Manage Databases

You perform many database management tasks using CloudKit Dashboard. For example, you can modify both the schema and records using CloudKit Dashboard. A container’s databases exist in both the development and the production environment. The operations you can perform depend on whether you are in the development or production environment.

Go to CloudKit Dashboard, sign in, and click the options to explore CloudKit Dashboard features.

../Art/Dashboard1.shot/Resources/shot_2x.png../Art/Dashboard1.shot/Resources/shot_2x.png

About the Development and Production Environments

The development environment is used to create a schema and add records for testing. The production environment is accessed by apps sold on the store. An app in development, can access either the development or the production environment. However, an app sold on the store can access only the production environment.

In the development environment, CloudKit automatically creates the schema for you based on the records that you save to the database. This feature allows you to iterate and refine your schema without having to explicitly create it. You can also use CloudKit Dashboard to modify and add records.

The first time you deploy the schema, the schema is copied to the production environment (records are not copied to the production environment). The next time you deploy the schema, the schema is merged with the production schema. To prevent conflicts, you can’t delete fields or record types in a development schema that were previously deployed to the production environment.

In the production environment, you can’t change the schema but you can add, modify, and delete records in the public database.

../Art/developer_workflow_2x.png../Art/developer_workflow_2x.png

When you run your CloudKit app through Xcode, it is automatically configured to use the development environment. When you export your app from Xcode for testing, you specify either the development or production environment. When you submit your app to the store, it is configured to use the production environment.

Select Your Container

All of the functions in CloudKit Dashboard apply to the currently selected container. Switch the container using the pop-up menu in the upper-left corner. CloudKit Dashboard displays all the containers belonging to all the Apple Developer Program teams you belong to. Be sure to select the container used by the app that you are developing before performing any of the tasks in this chapter.

Reset the Development Environment

If you use just-in-time schema to populate a database with records, as described in Initializating the Container, you can reset the development environment between runs of your app. If you have never deployed your development environment, resetting the development environment deletes all the records and record types. Otherwise, it deletes all the records and returns the schema to the state of the production environment.

To reset the development environment

  1. In CloudKit Dashboard, click "Reset…” in the Development environment.

  2. In the dialog that appears, read the warning, select the checkbox, and click Reset.

    ../Art/Reset2017.shot/Resources/shot_2x.png../Art/Reset2017.shot/Resources/shot_2x.png

Create and Delete Record Types

In the development environment, you can create, modify, and delete record types using CloudKit Dashboard.

To create a record type

  1. In CloudKit Dashboard, click Data under the Development environment.

  2. Select Record Types in the tab bar.

  3. Click the Create New Type button.

  4. Enter a name in the New Record Type field.

    ../Art/CreateRecord1.shot/Resources/shot_2x.png../Art/CreateRecord1.shot/Resources/shot_2x.png
  5. To add a field, click Add Field, enter a field name, and select a field type from the pop-up menu.

  6. To delete a field, click the Delete button (x) in the row of the field.

    If the field is deployed, the Delete button is disabled.

  7. Click Save Record Type.

You can delete a record type only in the development environment and only when that record type is not deployed. When you delete a record type, all its associated records are deleted from the database too.

To delete a record type

  1. In CloudKit Dashboard, click Data in the Development environment.

  2. Select Record Types in the tab bar.

  3. Select the record type you want to delete.

  4. Click the Delete Record Type button.

    If the record type is deployed, the delete option is disabled.

  5. In the dialog that appears, click Delete.

Add, Modify, and Delete Records

In the development and production environment, you can add, modify, and delete records in public databases using CloudKit Dashboard.

To create a record

  1. In CloudKit Dashboard click Data in the Development or Production environment.

  2. Select records from the tab bar.

  3. Click Create New Record… to start a new record.

    CloudKit Dashboard assigns a random UUID as the record name.

  4. Enter values in the text fields.

  5. For Date/Time types, enter the calendar date and the time values in separate text fields.

    ../Art/CreateRecord3.shot/Resources/shot_2x.png../Art/CreateRecord3.shot/Resources/shot_2x.png
  6. For Asset values, drag the file to the box or click Choose File to upload the file.

  7. For Location types, enter the latitude and longitude in separate text fields.

    The latitude ranges from -90 and 90, and longitude ranges from -180 to 180.

  8. Click Save.

To view, modify, or delete a record

  1. In CloudKit Dashboard, click Data in the Development or Production environment.

  2. Select records from the tab bar.

  3. Query for the record(s) to view, modify, or delete.

  4. Select the record you want to view, edit, or delete.

    The record fields appear in the detail area.

  5. To edit a record, enter new values in the text fields and click Save.

  6. To delete a record, click the Delete button and in the dialog that appears, click Delete.

Search Records

In the development and production environment, you can search for records that have string fields.

To search for records

  1. In CloudKit Dashboard, click Data in the Development or Production environment.

  2. Select records from the tab bar.

  3. Select the record type to query.

  4. Add filters or sort criteria to the query.

  5. Click Query Records button.

Recap

This chapter introduces you to managing your databases with CloudKit Dashboard. You learned how to: