---
epic: 7
story: 7.7
title: "iCloud Sync"
status: draft
---

## Epic 7 — macOS App (Swift/SwiftUI)
**Goal:** A beautiful, native macOS app that feels like it belongs on the platform.

### Story 7.7: iCloud Sync

As a **macOS user** with multiple Apple devices,
I want my CalcPad settings and sheets to sync via iCloud,
So that I can access my calculations on any device without manual import/export.

**Acceptance Criteria:**

**Given** the user is signed into iCloud on two Macs
**When** the user changes a CalcPad setting (e.g., angle mode) on Mac A
**Then** the setting syncs to Mac B via `NSUbiquitousKeyValueStore`
**And** Mac B reflects the updated setting without restarting

**Given** the user creates a new sheet on Mac A
**When** iCloud sync completes
**Then** the sheet appears in the sidebar on Mac B

**Given** the user edits a sheet on Mac A while Mac B is offline
**When** Mac B comes online
**Then** the changes sync to Mac B and the sheet is updated

**Given** the user edits different lines of the same sheet on Mac A and Mac B simultaneously
**When** both devices sync
**Then** non-overlapping edits are merged successfully
**And** the final document contains both sets of changes

**Given** the user edits the same line on Mac A and Mac B simultaneously
**When** both devices sync
**Then** a last-write-wins strategy is applied
**And** no data corruption occurs (one version is chosen cleanly)

**Given** the user is not signed into iCloud
**When** the app launches
**Then** sheets are stored locally only and no sync errors are shown
