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

DeprecatedReplacementReason
SwiftDataTableDataSource protocolDirect data patternBoilerplate-heavy, no diffing
reload() methodsetData(_:animatingDifferences:)Resets scroll, no animations
.largeScale().automatic(estimated:prefetchWindow:)Renamed for clarity
dataTable(_:highlightedColorForRowIndex:)defaultCellConfigurationMore flexible per-cell styling
dataTable(_:unhighlightedColorForRowIndex:)defaultCellConfigurationMore 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

AspectBefore (DataSource)After (Direct Data)
Lines of code~30+~5
Animated updatesNoYes
Scroll preservationNoYes
Cell-level diffingNoYes
Type safetyManualCompile-time

Migration Checklist

  • Remove SwiftDataTableDataSource conformance
  • Add Identifiable to your model types
  • Replace protocol methods with DataTableColumn definitions
  • Replace dataTable.reload() with dataTable.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)