Migrating to 0.9.0
Upgrade from earlier versions with this step-by-step guide.
What's New in 0.9.0
- Type-safe columns with
DataTableColumn - Animated diffing via
setData(_:animatingDifferences:) - Self-sizing cells with lazy measurement
- Scroll anchoring during updates
- Live cell editing support
- Default cell configuration for fonts, colours, and styling without custom cells
Breaking Changes
None. All existing APIs continue to work. New APIs are additive.
Deprecated APIs
| Deprecated | Replacement | Reason |
|---|---|---|
| SwiftDataTableDataSource protocol | Direct data pattern | Boilerplate-heavy, no diffing |
| reload() method | setData(_:animatingDifferences:) | Resets scroll, no animations |
| .largeScale() | .automatic(estimated:prefetchWindow:) | Renamed for clarity |
| dataTable(_:highlightedColorForRowIndex:) | defaultCellConfiguration | More flexible per-cell styling |
| dataTable(_:unhighlightedColorForRowIndex:) | defaultCellConfiguration | More flexible per-cell styling |
Migration Path
Step 1: Remove DataSource Protocol
Before:
class MyVC: UIViewController, SwiftDataTableDataSource {
var items: [Item] = []
let dataTable = SwiftDataTable()
override func viewDidLoad() {
super.viewDidLoad()
dataTable.dataSource = self
}
func numberOfColumns(in: SwiftDataTable) -> Int { 3 }
func numberOfRows(in: SwiftDataTable) -> Int { items.count }
// ... more boilerplate
}After:
class MyVC: UIViewController {
var items: [Item] = []
var dataTable: SwiftDataTable!
let columns: [DataTableColumn<Item>] = [
.init("Name", \.name),
.init("Age", \.age),
.init("City", \.city)
]
override func viewDidLoad() {
super.viewDidLoad()
dataTable = SwiftDataTable(data: items, columns: columns)
}
}Step 2: Add Identifiable Conformance
// Before
struct Item {
let name: String
let age: Int
}
// After
struct Item: Identifiable {
let id: Int // Add unique identifier
let name: String
let age: Int
}Step 3: Replace reload() with setData()
// Before
func refresh() {
items = fetchNewItems()
dataTable.reload() // No animation, scroll resets to top
}
// After
func refresh() {
items = fetchNewItems()
dataTable.setData(items, animatingDifferences: true)
// Smooth animation, scroll position preserved
}Benefits After Migration
| Aspect | Before (DataSource) | After (Direct Data) |
|---|---|---|
| Lines of code | ~30+ | ~5 |
| Animated updates | No | Yes |
| Scroll preservation | No | Yes |
| Cell-level diffing | No | Yes |
| Type safety | Manual | Compile-time |
Migration Checklist
- Remove
SwiftDataTableDataSourceconformance - Add
Identifiableto your model types - Replace protocol methods with
DataTableColumndefinitions - Replace
dataTable.reload()withdataTable.setData(_:animatingDifferences:) - Update
.largeScale()to.automatic(estimated:prefetchWindow:) - (Optional) Replace delegate colour methods with
defaultCellConfiguration - (Optional) Enable text wrapping:
config.textLayout = .wrap - (Optional) Enable auto heights:
config.rowHeightMode = .automatic(estimated: 44)