Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

SwiftadvancedmobileAI generated

Offline-First Note Sync with CloudKit

Build an iPhone notes app that works completely offline and syncs across your devices through iCloud, using Core Data with CloudKit (NSPersistentCloudKitContainer). Notes are saved locally the moment you type, edits made offline are pushed when the connection returns, and changes from your other devices arrive automatically. When the same note was edited on two devices before syncing, the app detects the conflict and lets you choose which version to keep or merge them, instead of silently losing text. You'll need an Apple developer account to use CloudKit. You'll learn Core Data with CloudKit, merge policies and persistent history tracking, conflict detection, testing sync across devices, and designing for offline use.

Estimate
~12.5h
Steps
6
Completed by
0
Proposed by
codeseed.app

SwiftUI · CoreData · CloudKit

Project roadmap

  1. 01

    Set up Core Data with CloudKit

    ~2h

    Create an iOS app with the iCloud capability (CloudKit, with a container) and Background Modes (remote notifications). Define a Core Data model with a Note entity (id, title, body, created and modified dates, a device id and a version counter), following CloudKit's rules (all attributes optional or with defaults, and no unique constraints). Load it with NSPersistentCloudKitContainer, and turn on persistent history tracking and remote change notifications. Done when: the app starts and the CloudKit schema appears in the CloudKit Console after running in development.

  2. 02

    Build the note editor

    ~2h

    Build a notes list (with @FetchRequest, sorted by modified date, and search) and an editor that saves changes a moment after typing stops, updating the modified date, version and device id. Add creating and deleting notes. Done when: notes can be created, edited, searched and deleted, and are saved locally.

  3. 03

    Configure syncing and merging

    ~2h

    Set the view context's automaticallyMergesChangesFromParent and a merge policy, and process persistent history changes when a remote change notification arrives, so edits from other devices appear in open screens. Show a small sync status (for example the time of the last change received) using NSPersistentCloudKitContainer's event notifications. Done when: a note edited on one device appears on another within a short time.

  4. 04

    Detect and resolve conflicts

    ~3h

    CloudKit merges records field by field with the latest change winning, which can lose text. Detect conflicts by keeping, for each note, the version you last saw from the cloud: when a remote change arrives for a note with unsynced local edits, keep both versions (saving the remote one as a conflict copy) and flag the note. Build a screen showing both versions side by side, letting the user keep one or merge them. Done when: editing the same note on two offline devices and then syncing shows the conflict, and resolving it keeps the chosen text.

  5. 05

    Handle offline changes

    ~1.5h

    Check that edits made in airplane mode are kept and pushed once the connection returns, deletions made offline sync correctly, and the app behaves well when the user isn't signed in to iCloud (working locally, with a message explaining that sync is off). Done when: offline edits and deletions sync after reconnecting, and the app works without iCloud.

  6. 06

    Test sync across devices

    ~2h

    Write unit tests for the conflict detection logic with an in-memory store, and a manual test plan in TESTING.md run on two devices or simulators signed in to the same test iCloud account: simple sync, offline edits, conflicting edits, deletions and signing out. Record the results. Done when: the unit tests pass, and every case in TESTING.md has been checked.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~12.5h · 6 steps

Tech stack

SwiftUICoreDataCloudKit