Implement, review, or improve CloudKit and iCloud sync in iOS/macOS apps. Use when working with CKContainer, CKRecord, CKQuery, CKSubscription, CKSyncEngine, CKShare, NSUbiquitousKeyValueStore, or iCloud Drive file coordination; when syncing SwiftData models via ModelConfiguration with cloudKitDatabase; when handling CKError codes for conflict resolution, network failures, or quota limits; or when checking iCloud account status before performing sync operations.
Detected risks:
A practical reference for implementing, reviewing, or improving CloudKit and iCloud sync in iOS and macOS apps, targeting iOS 26+ with Swift 6.3 while noting older availability where relevant. It starts with container and database setup, enabling iCloud + CloudKit capabilities and understanding the three databases a container exposes (public, private, shared) with their differing iCloud requirements and storage quotas, then covers CKRecord CRUD with the 1 MB per-record limit, custom record zones (which support atomic commits, change tracking, and sharing, unlike public databases), and CKQuery with its supported NSPredicate operators and encryption caveats.
Later sections address CKSubscription (query, database, and record-zone subscriptions plus silent-push handling in the app delegate) and CKSyncEngine (iOS 17+), described as the recommended sync approach for custom model data because it manages scheduling, retries, change tokens, and database subscriptions, while still leaving app-specific conflicts like CKError.serverRecordChanged to custom resolution. It also integrates SwiftData with CloudKit via ModelConfiguration, and covers NSUbiquitousKeyValueStore, iCloud Drive file coordination, account-status checks, error handling, and conflict resolution.
Use it when working with any of these CloudKit types, when handling CKError codes for conflict resolution, network failures, or quota limits, or before performing sync that depends on iCloud account status. The skill is structured as a contents-linked guide with concrete Swift examples throughout and rounds out with a common-mistakes section and a review checklist, making it suitable both for writing new sync code and for auditing existing integrations. Notable details include encryption eligibility rules: encrypted values cannot be queried or sorted, CKAsset is encrypted by default, and CKRecord.Reference cannot be encrypted because CloudKit needs it server-side.
iOS 26+ with Swift 6.3, with older availability noted where relevant; for example CKSyncEngine requires iOS 17+.
It is the recommended approach for syncing custom model data because it handles scheduling, retries, change tokens, and database subscriptions, though you still resolve app-specific conflicts like CKError.serverRecordChanged yourself.
Public (all users, app quota), Private (current user, user quota), and Shared (shared records, owner quota); private and shared require an iCloud account.
No; encrypted values cannot be queried or sorted, CKAsset is encrypted by default, and CKRecord.Reference cannot be encrypted because CloudKit needs it server-side.
Yes; it includes syncing SwiftData models via ModelConfiguration with a cloudKitDatabase, alongside CKRecord CRUD, subscriptions, and CKSyncEngine.
Quick Setup:
.claude/skills/Repository
dpearson2699/swift-ios-skills