2021 System ServicesDeveloper Tools
WWDC21 · 10 min · System Services / Developer Tools
Automate CloudKit tests with cktool and declarative schema
It’s never been easier to test your CloudKit containers. We’ll introduce you to cktool, a command-line utility that makes quick work of CloudKit configuration, and learn about the new schema language that allows you to rapidly prototype and evolve containers. We’ll also show you how to combine these tools and configure your containers before running tests in Xcode. To get the most out of this session, we recommend being familiar with CloudKit and its development and production environments, as well as a basic understanding of record and data types.
Watch at developer.apple.com ↗Code shown on screen · 5 snippets
cktool: Save tokens, get teams
xcrun cktool save-token --type management
xcrun cktool save-token --type user
xcrun cktool get-teams cktool: Export schema
xcrun cktool export-schema \
--team-id XYZ1234567 \
--container-id iCloud.com.WWDC21.Example \
--environment development \
--output-file schema.ckdb cktool: Create record
xcrun cktool create-record \
--team-id XYZ1234567 \
--container-id iCloud.com.WWDC21.Example \
--environment development \
--database-type public \
--record-type Book \
--fields-json '{
"title": { "type": "stringType", "value": "Treasure Island" },
"pageCount": { "type": "int64Type", "value": 304 }
}' cktool: Test pre-action script
xcrun cktool reset-schema \
--team-id XYZ1234567 \
--container-id iCloud.com.WWDC21.Example
xcrun cktool import-schema \
--team-id XYZ1234567 \
--container-id iCloud.com.WWDC21.Example \
--environment development \
--file $PROJECT_DIR/Example/CloudKitSchema.ckdb
xcrun cktool create-record \
--team-id XYZ1234567 \
--container-id iCloud.com.WWDC21.Example \
--environment development \
--database-type public \
--record-type Book \
--fields-json '{
"title": { "type": "stringType", "value": "Great Expectations" },
"pageCount": { "type": "int64Type", "value": 544 },
"description": { "type": "stringType", "value": "Depiction of the education of an orphan nicknamed Pip" },
"publishedOn": { "type": "timestampType", "value": "1860-12-01T03:23:07.415Z" },
"reviewStatus": { "type": "int64Type", "value": 1 }
}' Schema language file: Example
DEFINE SCHEMA
RECORD TYPE Book (
"___createTime" TIMESTAMP,
"___createdBy" REFERENCE,
"___etag" STRING,
"___modTime" TIMESTAMP,
"___modifiedBy" REFERENCE,
"___recordID" REFERENCE QUERYABLE,
description STRING,
pageCount INT64,
publishedOn TIMESTAMP,
reviewStatus INT64,
// A single-line comment, for humans
title STRING QUERYABLE,
GRANT WRITE TO "_creator",
GRANT CREATE TO "_icloud",
GRANT READ TO "_world"
); Resources
Related sessions
-
16 min -
7 min