Skip to content

Commit 24e3e44

Browse files
pavankatariaclaude
andcommitted
Update all documentation to use typed API
Replace deprecated array-based initializer (`init(data:headerTitles:)`) with the new typed API (`init(data:columns:)`) across all documentation: - README.md: Update Quick Start and examples - GettingStarted.md: Use typed API with Identifiable models - QuickStart.md: Update all examples to typed API - AdvancedPatterns.md: Update pattern examples - ColumnSorting.md, ConfigurationReference.md, CustomCells.md, RowSelection.md, SearchIntegration.md, Styling.md, TextWrapping.md: Replace deprecated API calls Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 01573bf commit 24e3e44

File tree

11 files changed

+68
-65
lines changed

11 files changed

+68
-65
lines changed

README.md

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

85-
// Simple array-based table
86-
let data = [
87-
["Alice", "Engineer", "London"],
88-
["Bob", "Designer", "Paris"],
89-
["Carol", "Manager", "Berlin"]
90-
]
91-
let dataTable = SwiftDataTable(
92-
data: data,
93-
headerTitles: ["Name", "Role", "City"]
94-
)
95-
view.addSubview(dataTable)
96-
```
97-
98-
Or with type-safe columns:
99-
100-
```swift
10185
struct Employee: Identifiable {
10286
let id: String
10387
let name: String
10488
let role: String
10589
let salary: Int
10690
}
10791

92+
// Define columns with type-safe key paths
10893
let columns: [DataTableColumn<Employee>] = [
10994
.init("Name", \.name),
11095
.init("Role", \.role),
11196
.init("Salary") { "£\($0.salary)" }
11297
]
11398

114-
let dataTable = SwiftDataTable(data: employees, columns: columns)
99+
// Create table with columns
100+
let dataTable = SwiftDataTable(columns: columns)
101+
view.addSubview(dataTable)
102+
103+
// Load data with animation
104+
dataTable.setData(employees, animatingDifferences: true)
115105
```
116106

117107
Update data with animated diffing:
118108

119109
```swift
120-
// Load initial data
121-
var employees: [Employee] = []
122-
dataTable.setData(employees)
123-
124-
// Fetch and update
110+
// Fetch and update - rows animate in/out automatically
125111
employees = await api.fetchEmployees()
126112
dataTable.setData(employees, animatingDifferences: true)
127113

@@ -130,6 +116,8 @@ employees.append(newEmployee)
130116
dataTable.setData(employees, animatingDifferences: true)
131117
```
132118

119+
For dynamic data (CSV, JSON, queries), see [Working with Data](https://pavankataria.github.io/SwiftDataTables/documentation/swiftdatatables/workingwithdata).
120+
133121
## Install
134122

135123
### Swift Package Manager
@@ -305,7 +293,7 @@ SwiftDataTables supports native iOS navigation bar search via UISearchController
305293
override func viewDidLoad() {
306294
super.viewDidLoad()
307295

308-
let dataTable = SwiftDataTable(data: myData, headerTitles: headers)
296+
let dataTable = SwiftDataTable(columns: columns)
309297
view.addSubview(dataTable)
310298

311299
// One line to enable navigation bar search
@@ -331,7 +319,7 @@ navigationItem.searchController = searchController
331319

332320
## Data Source methods (Deprecated)
333321

334-
> **Note**: The `SwiftDataTableDataSource` protocol is deprecated in v0.9.0. Use the direct data pattern with `init(data:headerTitles:)` or the typed API with `init(data:columns:)` instead. See the [Quick Start](#quick-start) section above for examples.
322+
> **Note**: The `SwiftDataTableDataSource` protocol is deprecated in v0.9.0. Use the typed API with `init(columns:)` and `setData(_:animatingDifferences:)` instead. See the [Quick Start](#quick-start) section above for examples.
335323
336324
The deprecated protocol is shown below for reference:
337325

SwiftDataTables/SwiftDataTables.docc/AdvancedPatterns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ class AccessibleTableVC: UIViewController {
429429
UIColor.label.withAlphaComponent(0.05)
430430
]
431431

432-
dataTable = SwiftDataTable(data: myData, headerTitles: headers, options: config)
432+
dataTable = SwiftDataTable(columns: columns, options: config)
433433

434434
// VoiceOver support
435435
dataTable.isAccessibilityElement = false

SwiftDataTables/SwiftDataTables.docc/ColumnSorting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Sorting is enabled by default. Users tap a column header to sort ascending, tap
99
## Default Behavior
1010

1111
```swift
12-
let dataTable = SwiftDataTable(data: myData, headerTitles: headers)
12+
let dataTable = SwiftDataTable(columns: columns)
1313
// Sorting is enabled automatically
1414
```
1515

SwiftDataTables/SwiftDataTables.docc/ConfigurationReference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Complete reference of all configuration options in DataTableConfiguration.
1111
```swift
1212
var config = DataTableConfiguration()
1313
// Modify properties...
14-
let dataTable = SwiftDataTable(data: myData, headerTitles: headers, options: config)
14+
let dataTable = SwiftDataTable(columns: columns, options: config)
1515
```
1616

1717
## Sorting Options

SwiftDataTables/SwiftDataTables.docc/CustomCells.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ var config = DataTableConfiguration()
104104
config.cellSizingMode = .autoLayout(provider: provider)
105105
config.rowHeightMode = .automatic(estimated: 60)
106106

107-
let dataTable = SwiftDataTable(data: myData, headerTitles: headers, options: config)
107+
let dataTable = SwiftDataTable(columns: columns, options: config)
108108
```
109109

110110
## How Auto Layout Sizing Works

SwiftDataTables/SwiftDataTables.docc/GettingStarted.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,35 @@ dependencies: [
3333
import SwiftDataTables
3434
```
3535

36-
### Step 2: Create Sample Data
36+
### Step 2: Define Your Model
3737

38-
SwiftDataTables works with simple 2D arrays:
38+
Create a model conforming to `Identifiable`:
3939

4040
```swift
41-
let data = [
42-
["Alice", "Engineer", "London"],
43-
["Bob", "Designer", "Paris"],
44-
["Carol", "Manager", "Berlin"]
41+
struct Employee: Identifiable {
42+
let id: Int
43+
let name: String
44+
let role: String
45+
let city: String
46+
}
47+
48+
let employees = [
49+
Employee(id: 1, name: "Alice", role: "Engineer", city: "London"),
50+
Employee(id: 2, name: "Bob", role: "Designer", city: "Paris"),
51+
Employee(id: 3, name: "Carol", role: "Manager", city: "Berlin")
4552
]
46-
let headers = ["Name", "Role", "City"]
4753
```
4854

49-
### Step 3: Create the Table
55+
### Step 3: Define Columns and Create the Table
5056

5157
```swift
52-
let dataTable = SwiftDataTable(
53-
data: data,
54-
headerTitles: headers
55-
)
58+
let columns: [DataTableColumn<Employee>] = [
59+
.init("Name", \.name),
60+
.init("Role", \.role),
61+
.init("City", \.city)
62+
]
63+
64+
let dataTable = SwiftDataTable(data: employees, columns: columns)
5665
```
5766

5867
### Step 4: Add to Your View

SwiftDataTables/SwiftDataTables.docc/QuickStart.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,37 @@ Jump straight into code with these ready-to-use examples.
66

77
This page provides copy-paste examples for common scenarios. Each example is self-contained and ready to use.
88

9-
## Basic Table with String Arrays
9+
## Basic Table
1010

1111
The simplest way to display data:
1212

1313
```swift
1414
import SwiftDataTables
1515

16+
struct Product: Identifiable {
17+
let id: Int
18+
let name: String
19+
let price: Int
20+
let status: String
21+
}
22+
1623
class BasicTableViewController: UIViewController {
24+
let products = [
25+
Product(id: 1, name: "iPhone 15", price: 999, status: "In Stock"),
26+
Product(id: 2, name: "MacBook Pro", price: 1999, status: "Limited"),
27+
Product(id: 3, name: "iPad Air", price: 599, status: "In Stock")
28+
]
29+
30+
let columns: [DataTableColumn<Product>] = [
31+
.init("Product", \.name),
32+
.init("Price") { "$\($0.price)" },
33+
.init("Status", \.status)
34+
]
35+
1736
override func viewDidLoad() {
1837
super.viewDidLoad()
1938

20-
let data = [
21-
["iPhone 15", "999", "In Stock"],
22-
["MacBook Pro", "1999", "Limited"],
23-
["iPad Air", "599", "In Stock"]
24-
]
25-
26-
let dataTable = SwiftDataTable(
27-
data: data,
28-
headerTitles: ["Product", "Price", "Status"]
29-
)
39+
let dataTable = SwiftDataTable(data: products, columns: columns)
3040

3141
view.addSubview(dataTable)
3242
dataTable.frame = view.bounds
@@ -155,11 +165,7 @@ class CustomTableViewController: UIViewController {
155165
UIColor.systemGray6
156166
]
157167

158-
let dataTable = SwiftDataTable(
159-
data: myData,
160-
headerTitles: headers,
161-
options: config
162-
)
168+
let dataTable = SwiftDataTable(data: items, columns: columns, options: config)
163169

164170
view.addSubview(dataTable)
165171
}
@@ -177,7 +183,7 @@ class SearchTableViewController: UIViewController {
177183
override func viewDidLoad() {
178184
super.viewDidLoad()
179185

180-
dataTable = SwiftDataTable(data: myData, headerTitles: headers)
186+
dataTable = SwiftDataTable(columns: columns)
181187
view.addSubview(dataTable)
182188
dataTable.frame = view.bounds
183189

SwiftDataTables/SwiftDataTables.docc/RowSelection.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MyViewController: UIViewController, SwiftDataTableDelegate {
1616

1717
override func viewDidLoad() {
1818
super.viewDidLoad()
19-
dataTable = SwiftDataTable(data: myData, headerTitles: headers)
19+
dataTable = SwiftDataTable(columns: columns)
2020
dataTable.delegate = self
2121
}
2222
}

SwiftDataTables/SwiftDataTables.docc/SearchIntegration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var config = DataTableConfiguration()
1818
config.shouldShowSearchSection = true // Default
1919
config.shouldSearchHeaderFloat = true // Stays visible while scrolling
2020

21-
let dataTable = SwiftDataTable(data: myData, headerTitles: headers, options: config)
21+
let dataTable = SwiftDataTable(columns: columns, options: config)
2222
```
2323

2424
### Hiding the Search Bar
@@ -38,7 +38,7 @@ class MyViewController: UIViewController {
3838
override func viewDidLoad() {
3939
super.viewDidLoad()
4040

41-
dataTable = SwiftDataTable(data: myData, headerTitles: headers)
41+
dataTable = SwiftDataTable(columns: columns)
4242
view.addSubview(dataTable)
4343

4444
// One line to enable navigation bar search

SwiftDataTables/SwiftDataTables.docc/Styling.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ config.highlightedAlternatingRowColors = [
2727
UIColor.systemBlue.withAlphaComponent(0.12)
2828
]
2929

30-
let dataTable = SwiftDataTable(data: myData, headerTitles: headers, options: config)
30+
let dataTable = SwiftDataTable(columns: columns, options: config)
3131
```
3232

3333
### More Than Two Colors
@@ -194,7 +194,7 @@ config.heightOfInterRowSpacing = 1
194194
config.heightForSectionHeader = 48
195195
config.heightForSectionFooter = 48
196196

197-
let dataTable = SwiftDataTable(data: myData, headerTitles: headers, options: config)
197+
let dataTable = SwiftDataTable(columns: columns, options: config)
198198
```
199199

200200
## Example: Minimal Style
@@ -215,7 +215,7 @@ config.shouldShowHorizontalScrollBars = false
215215
// No inter-row spacing
216216
config.heightOfInterRowSpacing = 0
217217

218-
let dataTable = SwiftDataTable(data: myData, headerTitles: headers, options: config)
218+
let dataTable = SwiftDataTable(columns: columns, options: config)
219219
```
220220

221221
## Example: High-Density Data
@@ -237,7 +237,7 @@ config.minColumnWidth = 50
237237
// Hide search to maximize data area
238238
config.shouldShowSearchSection = false
239239

240-
let dataTable = SwiftDataTable(data: myData, headerTitles: headers, options: config)
240+
let dataTable = SwiftDataTable(columns: columns, options: config)
241241
```
242242

243243
## See Also

0 commit comments

Comments
 (0)