Skip to main content
BoutiqueDB includes built-in sync support for Apple’s CloudKit via CKSyncEngine. This enables multi-device data sync for iOS and macOS applications directly through the user’s personal iCloud account.

Architecture Overview

BoutiqueDB CloudKit Sync uses Change Data Capture (turso_cdc) to convert local SQLite row mutations into CloudKit CKRecord mutations:

Step-by-Step Configuration

1

Enable CloudKit Capability in Xcode

  1. Open your main App target in Xcode.
  2. Go to Signing & Capabilities > + Capability > iCloud.
  3. Check CloudKit and select or create an iCloud Container (e.g. iCloud.com.example.MyApp).
2

Register Synced Schemas

Specify which @Table schemas should be synchronized to CloudKit:
SyncSetup.swift
3

Initialize & Attach Sync Engine

Attach the BoutiqueDBSyncEngine to your database instance:
AppSync.swift

Background sync

For automatic multi-device sync, register for remote notifications and background refresh:
AppDelegate.swift
On macOS, wire handleRemoteNotification(userInfo:) to NSApplicationDelegate.application(_:didReceiveRemoteNotification:) and call scheduleBackgroundSync(interval:) to set up an NSBackgroundActivityScheduler.

Conflict Resolution & Device Testing

By default, BoutiqueDB uses record modification timestamps to resolve edit conflicts between multiple devices. Newer local or remote timestamps take precedence.
CloudKit sync requires an active iCloud account signed in on an actual iOS device or macOS user account. Simulator sync requires signing into an Apple ID under iOS Settings.
Private Database Privacy: All records are synced directly into the user’s private iCloud database container. No user data is stored on external third-party servers!