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
- Open your main App target in Xcode.
- Go to Signing & Capabilities > + Capability > iCloud.
- 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
handleRemoteNotification(userInfo:) to NSApplicationDelegate.application(_:didReceiveRemoteNotification:) and call scheduleBackgroundSync(interval:) to set up an NSBackgroundActivityScheduler.
Conflict Resolution & Device Testing
Last-Write-Wins Conflict Handling
Last-Write-Wins Conflict Handling
By default, BoutiqueDB uses record modification timestamps to resolve edit conflicts between multiple devices. Newer local or remote timestamps take precedence.
Testing Sync on Physical Devices
Testing Sync on Physical Devices
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!

