Skip to content
SwiftSkills

CloudKit with AI agents

CloudKit moves structured app and user data into iCloud containers so people can use it on more than one device, and so you can store data in a public area every user can read. It does not replace your local model objects and needs the network. Start from Apple’s CloudKit docs, then compare Apple Docs MCP, Sosumi, ApKI and swiftui-pro.

Last updated:

Apple facts are from "CloudKit", "Enabling CloudKit in Your App", "Deciding whether CloudKit is right for your app", "Managing iCloud Containers with CloudKit Database App", "CKContainer", "privateCloudDatabase", "publicCloudDatabase", "sharedCloudDatabase", "CKDatabase", "CKRecord", "CKRecordZone" and "CKShare" on developer.apple.com. Tool facts are from each README. Stars as of 23 Nov 2026.

What Apple documents

  • The CloudKit framework stores structured app and user data in iCloud containers that all users of your app can share. Apple’s overview says you use it to store your app’s existing data in the cloud so the user can access it on multiple devices, and that you can also store data in a public area where all users can access it. CloudKit isn’t a replacement for your app’s existing data objects; it provides complementary services for moving data to and from iCloud servers. It provides minimal offline caching, and it relies on the presence of the network and, optionally, a valid iCloud account. A valid iCloud account is only necessary when you want to save data that is specific to a single user; apps can always store data in a public area that is readable by all users. Records are at the heart of the transactions: a record is a dictionary of key-value pairs, defined by CKRecord. The classes of the framework aren’t for subclassing; use them as-is. CloudKit is documented for iOS 8, iPadOS 8, Mac Catalyst 13, macOS 10.10, tvOS 9, visionOS 1 and watchOS 3.

  • Enabling CloudKit in Your App says you add the iCloud capability on the Signing and Capabilities tab, then select the CloudKit checkbox. That adds the CloudKit capability, creates an iCloud container named with your app’s bundle identifier prefixed with “iCloud.”, and also adds the Push Notifications capability. Check the box next to the container name. An app has one default container; once created, you can’t delete or rename a container. You need an iCloud account on the simulator or device to save records. Confirm the container in CloudKit Console at icloud.developer.apple.com.

  • CKContainer is a conduit to your app’s databases. Each container provides a public and a private database, and also a sharedCloudDatabase (iOS 10 and later). The public database is always available, regardless of whether the device has an iCloud account; without an account the app can fetch and query public records but can’t save changes. Its contents are readable by all users of the app, and that data counts toward the app’s iCloud storage quota. The private database is only available with an iCloud account, is the user’s personal storage, isn’t visible in the developer portal, and counts toward the user’s quota. The shared database holds records other iCloud users share with the current user through a CKShare; it also requires an iCloud account, and its data counts toward the app’s quota. If there isn’t an iCloud account, the private and shared properties still return a database, but any attempt to use it results in an error; check with accountStatus(completionHandler:).

  • You don’t create or subclass CKDatabase; you get the three databases from the container. A CKRecordZone is a database partition that contains related records. During development you can add new keys to records at any time; when you deploy to production, the server returns an error if you specify an unknown record type or unknown keys. Apple’s container documentation says the Simulator works only with the development environment, and that you should test production behavior from a device. The production server generates errors when the app tries to add record types or new fields to existing record types.

  • Deciding whether CloudKit is right for your app distinguishes iCloud Documents and iCloud key-value storage from CloudKit itself. For a complex graph of model objects, Apple lists three CloudKit options: NSPersistentCloudKitContainer when you don’t need granular control or already use NSPersistentContainer; CKSyncEngine when you retain control of your data and want the engine to schedule sync operations for the private and shared databases; and CKDatabase, CKOperation and related types when you need full control and will fetch, send, resolve conflicts and persist tokens yourself. How you set up NSPersistentCloudKitContainer stays in Core Data with AI agents. SwiftData stays in SwiftData with AI agents. HomeKit’s shared home configuration database is not an iCloud container; see HomeKit with AI agents.

  • Managing iCloud Containers with CloudKit Database App says CloudKit Database is a web-based tool in CloudKit Console at icloud.developer.apple.com. You can view and edit the development schema, view the production schema, inspect test data, view logs and metrics, and deploy a schema to production. Don’t use it as a general data editor; creating or deleting records there is meant to help debug a schema during design.

Rules for AGENTS.md

Code

- Use CloudKit to move structured app and user data to iCloud containers. It is not a replacement for local model objects, and it needs the network. Add the iCloud capability, select CloudKit, and use the container whose name is the bundle identifier prefixed with iCloud. Once created, a container cannot be deleted or renamed.
- Get public, private and shared CKDatabase objects from CKContainer. Do not create or subclass CKDatabase or other CloudKit classes. A valid iCloud account is required to save user-specific data; the public database can be read without one. Check accountStatus(completionHandler:) before using the private or shared database.
- During development you may add record types and fields; production returns errors for unknown types or keys. Test production behavior on a device. The Simulator works only with the development environment.
- If the app already uses NSPersistentContainer and does not need granular sync control, leave that path to the Core Data rules (NSPersistentCloudKitContainer). Leave SwiftData to the SwiftData rules. Look up Apple's CloudKit docs first.

Step 1: ground the agent in Apple's CloudKit docs

Install Apple Docs MCP or Sosumi and ask it to open “CloudKit”, “Enabling CloudKit in Your App”, “Deciding whether CloudKit is right for your app”, CKContainer, CKDatabase and CKRecord. Confirm whether the work is CloudKit records and databases, or a Core Data / SwiftData sync path that belongs on those guides.

Step 2: add the capability and confirm the container

Have the agent add the iCloud capability, select CloudKit, and check the generated iCloud. container. Sign in with an iCloud account on the simulator or device before saving records. Confirm the container in CloudKit Console. Do not let the agent invent a container name, or assume a container can be renamed or deleted later.

Step 3: choose a database and a sync approach

Read and write through the matching CKDatabase from CKContainer. Use the public database for data all users can read, the private database for user-specific data, and the shared database only for CKShare content. If the project already persists with NSPersistentContainer and does not need granular sync control, stop and follow the Core Data guide instead of hand-rolling CKOperation calls.

Step 4: review the SwiftUI around the CloudKit flow

Run swiftui-pro on the screens that show or edit CloudKit-backed data. Do not replace CloudKit container setup or schema work with SwiftUI-only advice.

Tools compared (4)

ToolBest forAgents (README)Install (README)LicenseStarsLast push
Apple Docs MCP (kimsungwhee)Look up CloudKit containers, databases, records and the enabling stepsClaude Code, Cursor, VS Code, Windsurfclaude mcp add apple-docs -- npx -y @kimsungwhee/apple-docs-mcp@latestMIT138617 Mar 2026 ⚠
sosumi.ai (NSHipster)Pull CloudKit docs as Markdownany MCP hostnpx -y mcp-remote https://sosumi.ai/mcpMIT49213 Nov 2026
ApKI (Gucky)Route the agent to official Apple developer resourcesCodex, Claude Codenpx skills add https://github.com/Gucky/ApKI --skill apkiMIT23 Nov 2026
swiftui-pro (twostraws)Modern SwiftUI around the screens that show CloudKit-backed dataClaude Code, Cursor, Codex, Gemininpx skills add https://github.com/twostraws/SwiftUI-Agent-Skill --skill swiftui-proMIT661626 Oct 2026

⚠ = no push in the last 4 weeks.

Which one to pick

  • Official API lookup → Apple Docs MCP or Sosumi.

  • A short route into Apple's current developer resources → ApKI.

  • SwiftUI around the screens that show CloudKit-backed data → swiftui-pro.

A prompt that keeps the agent honest

Code

Add CloudKit to this existing iOS app. Add the iCloud capability, select CloudKit, and use the default container named with the bundle identifier prefixed with iCloud. Get the public, private and shared CKDatabase objects from CKContainer; do not create or subclass CKDatabase. Require an iCloud account before saving user-specific records, and call accountStatus(completionHandler:) first. During development you may add record types and fields; do not assume production will accept unknown keys. Test production behavior on a device. If the app already uses NSPersistentContainer and does not need granular sync control, follow the Core Data path with NSPersistentCloudKitContainer instead of hand-rolled CKOperation calls. Leave SwiftData to the SwiftData guide. Look up “CloudKit”, “Enabling CloudKit in Your App”, “Deciding whether CloudKit is right for your app”, CKContainer, CKDatabase and CKRecord in Apple's docs first.

FAQ

Do I need an iCloud account?
Yes, if you want to save user-specific data. Apple’s CloudKit overview says a valid iCloud account is only necessary when you want to save data that is specific to a single user, and that apps can always store data in a public area that is readable by all users. The public database is always available: without an iCloud account the app can fetch and query public records, but it can’t save changes. The private and shared databases require an iCloud account; if none is present those database objects still exist, but using them results in an error. Check with `accountStatus(completionHandler:)`.
How do I enable CloudKit in Xcode?
Apple’s enabling article says you add the iCloud capability on the Signing and Capabilities tab, then select the CloudKit checkbox. That adds the CloudKit capability, creates an iCloud container named with your app’s bundle identifier prefixed with `iCloud.`, and also adds the Push Notifications capability. Check the box next to the container name. Once created, you can’t delete or rename a container. You need an iCloud account on the simulator or device to save records. Confirm the container in CloudKit Console at icloud.developer.apple.com.
What is the difference between the public, private and shared databases?
Each `CKContainer` exposes three `CKDatabase` objects. The public database is available with or without an iCloud account; its contents are readable by all users of the app, and its data counts toward the app’s iCloud storage quota. The private database is the user’s personal storage, only available with an iCloud account, and its data counts toward that user’s quota; it isn’t visible in the developer portal. The shared database holds records other iCloud users share with the current user through a `CKShare`; it also requires an iCloud account, and its data counts toward the app’s quota. You don’t create or subclass `CKDatabase`; you get the databases from the container.
Should I use CloudKit or Core Data to sync?
Apple’s deciding article says CloudKit is one option for a complex graph of model objects. If you don’t need granular control over how and when data syncs, or the app already uses `NSPersistentContainer`, prefer `NSPersistentCloudKitContainer`, which provides a fully managed schema and a local replica. `CKSyncEngine` keeps your data model under your control and automatically schedules sync operations for the private and shared databases. `CKDatabase`, `CKOperation` and related types give full control but require you to fetch and send records, resolve conflicts and handle tokens yourself. This guide covers the CloudKit types. Leave `NSPersistentCloudKitContainer` setup to the Core Data guide, and any SwiftData sync work to the SwiftData guide.
Which tools should the agent use first?
Start with Apple Docs MCP or Sosumi so the agent opens CloudKit, Enabling CloudKit in Your App, Deciding whether CloudKit is right for your app, `CKContainer`, `CKDatabase`, `CKRecord` and `CKSyncEngine` instead of inventing a sync stack. Use ApKI if the agent needs a short route into current official Apple developer resources. Use swiftui-pro only for the SwiftUI screens around the CloudKit flow, not as a substitute for CloudKit setup.