Skip to content

Commit b746eb6

Browse files
pavankatariaclaude
andcommitted
Add 'why' explanations throughout documentation
Documentation now explains the purpose behind each concept: - Why Identifiable? Enables row tracking for animated updates - Why key paths? Compile-time safety catches typos at build time - Why setData with animating? Calculates exactly what changed Updated files: - README.md: Quick Start with inline explanations - GettingStarted.md: Step-by-step with reasoning - QuickStart.md: Brief context for each example Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 24e3e44 commit b746eb6

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,36 +82,36 @@ Display grid-like data with sorting, searching, and smooth animations - all in j
8282
```swift
8383
import SwiftDataTables
8484

85+
// Identifiable enables row tracking for animated updates
8586
struct Employee: Identifiable {
8687
let id: String
8788
let name: String
8889
let role: String
8990
let salary: Int
9091
}
9192

92-
// Define columns with type-safe key paths
93+
// Key paths provide compile-time safety - typos caught at build time
9394
let columns: [DataTableColumn<Employee>] = [
9495
.init("Name", \.name),
9596
.init("Role", \.role),
96-
.init("Salary") { "£\($0.salary)" }
97+
.init("Salary") { "£\($0.salary)" } // Closures for formatted values
9798
]
9899

99-
// Create table with columns
100100
let dataTable = SwiftDataTable(columns: columns)
101101
view.addSubview(dataTable)
102102

103-
// Load data with animation
103+
// Rows animate in - scroll position preserved
104104
dataTable.setData(employees, animatingDifferences: true)
105105
```
106106

107-
Update data with animated diffing:
107+
Update data with animated diffing - SwiftDataTables calculates exactly what changed:
108108

109109
```swift
110-
// Fetch and update - rows animate in/out automatically
110+
// Only changed rows animate - others stay in place
111111
employees = await api.fetchEmployees()
112112
dataTable.setData(employees, animatingDifferences: true)
113113

114-
// Append new items
114+
// New row slides in at the end
115115
employees.append(newEmployee)
116116
dataTable.setData(employees, animatingDifferences: true)
117117
```

SwiftDataTables/SwiftDataTables.docc/GettingStarted.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ import SwiftDataTables
3535

3636
### Step 2: Define Your Model
3737

38-
Create a model conforming to `Identifiable`:
38+
Your model must conform to `Identifiable`. This enables SwiftDataTables to track individual rows - when you update data, rows animate smoothly (insertions slide in, deletions slide out) instead of the whole table reloading.
3939

4040
```swift
4141
struct Employee: Identifiable {
42-
let id: Int
42+
let id: Int // Any Hashable type works: Int, String, UUID, etc.
4343
let name: String
4444
let role: String
4545
let city: String
@@ -54,9 +54,11 @@ let employees = [
5454

5555
### Step 3: Define Columns and Create the Table
5656

57+
Each `DataTableColumn` defines a column header and how to extract the value from your model. Using key paths (`\.name`) gives you compile-time safety - typos are caught at build time, not runtime.
58+
5759
```swift
5860
let columns: [DataTableColumn<Employee>] = [
59-
.init("Name", \.name),
61+
.init("Name", \.name), // Header: "Name", Value: employee.name
6062
.init("Role", \.role),
6163
.init("City", \.city)
6264
]

SwiftDataTables/SwiftDataTables.docc/QuickStart.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This page provides copy-paste examples for common scenarios. Each example is sel
88

99
## Basic Table
1010

11-
The simplest way to display data:
11+
The simplest way to display data. Models conform to `Identifiable` so SwiftDataTables can track rows for animated updates:
1212

1313
```swift
1414
import SwiftDataTables
@@ -47,7 +47,7 @@ class BasicTableViewController: UIViewController {
4747

4848
## Type-Safe Table with Models
4949

50-
Use your own model types for compile-time safety:
50+
Key paths like `\.name` give you compile-time safety - if you rename a property, Xcode catches it immediately instead of failing silently at runtime:
5151

5252
```swift
5353
import SwiftDataTables
@@ -87,7 +87,7 @@ class TypedTableViewController: UIViewController {
8787

8888
## Dynamic Updates with Animation
8989

90-
Update data smoothly without losing scroll position:
90+
Because your model is `Identifiable`, SwiftDataTables calculates exactly what changed and animates only those rows. Scroll position is preserved - your users won't lose their place:
9191

9292
```swift
9393
class DynamicTableViewController: UIViewController {
@@ -210,7 +210,7 @@ config.fixedColumns = .both(left: 1, right: 1)
210210

211211
## Large Datasets (100k+ Rows)
212212

213-
Optimize for massive datasets:
213+
For massive datasets, use lazy measurement. Only visible rows are measured; others use the estimated height until they scroll into view. The `prefetchWindow` controls how many rows ahead to pre-measure:
214214

215215
```swift
216216
var config = DataTableConfiguration()

0 commit comments

Comments
 (0)