CloudKit
01 / 02

CloudKit: Sync, Sharing & Conflict Resolution

CloudKit: Sync, Sharing & Conflict Resolution

Push-Driven Sync

A CKSubscription registers interest in record changes -- CloudKit sends a silent push notification when matching data changes, and the app fetches the incremental delta via a change-token-based operation, rather than polling constantly.

Sharing With CKShare

CKShare lets an app share a record zone or hierarchy with specific other iCloud users, with configurable read/write permissions -- the building block for collaborative features like a shared note or project.

Handling Write Conflicts

CloudKit uses optimistic concurrency via record change tags. A conflicting save (the same record edited on two offline devices) returns an error containing the server's current version -- the app's logic decides how to reconcile the two.

Querying Records

let predicate = NSPredicate(format: "title == %@", "Groceries")
let query = CKQuery(recordType: "Note", predicate: predicate)

privateDB.perform(query, inZoneWith: nil) { records, error in
  // handle matching records
}

References Between Records

A CKRecord.Reference links one record to another -- similar to a foreign key -- letting an app model related data, like a comment record referencing its parent post record.

The Cross-Platform Trade-off

Because CloudKit is deeply tied to Apple's iCloud infrastructure and Apple ID auth, an app that also needs an Android or web client typically can't reuse the same CloudKit backend for those platforms -- a real limitation worth weighing upfront.

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free