ListDataSource is a lightweight and modular Swift package designed to simplify UITableView and UICollectionView data handling. It provides built-in support for pagination, refreshing, empty and error states, while embracing Swift Concurrency and Combine.
- ✅ Unified data handling for
UITableViewandUICollectionView - 🔄 Supports pagination, refreshing, and loading more
- 📡 Reactive updates via Combine and AsyncStream
- 🧱 Strongly typed cell/section abstractions
⚠️ Built-in support for empty and error UI states- 🧪 Easy to test and mock
TableViewDataSource / CollectionViewDataSource
└── State Enum (loading, loaded, error, empty, etc.)
└── Sections and Pagination
Add to your Package.swift:
.package(url: "https://github.com/bamohammad/ListDataSource.git", from: "1.0.0"),let dataSource = TableViewDataSourceFactory.makeDataSource()
dataSource.attach(to: tableView)
dataSource.send(.loading())
dataSource.update(sections: [DefaultSection(items: yourItems)], pagination: .initial)let dataSource = CollectionViewDataSourceFactory.makeDataSource()
dataSource.attach(to: collectionView)
dataSource.send(.loading())
dataSource.update(sections: [DefaultCollectionSection(items: yourItems)], pagination: .initial)struct MyItem { let title: String }
final class MyCell: UITableViewCell, ConfigurableTableCell {
func configure(with item: MyItem) {
textLabel?.text = item.title
}
}
let item = CellItemFactory.make(cellType: MyCell.self, item: MyItem(title: "Example"))final class MyCell: UICollectionViewCell, ConfigurableCollectionCell {
func configure(with item: MyItem) {
// configure UI
}
}
let item = CollectionCellItemFactory.make(cellType: MyCell.self, item: MyItem(title: "Item"))dataSource.statePublisher
.sink { state in
// react to state
}
.store(in: &cancellables)Task {
for await state in dataSource.observeState() {
// react to state
}
}.initial.loading(previousSections:).refreshing(currentSections:).loadingMore(currentSections:, pagination:).loaded(sections:, pagination:).empty(config:).error(error:, previousSections:).loadingMoreError(error:, currentSections:, pagination:)
let config = TableViewDataSource.Configuration(
loadingHeaderHeight: 50,
showLoadingFooter: true,
emptyStateViewProvider: { config in
let view = UIView()
view.backgroundColor = config.backgroundColor
return view
}
)| Component | Description |
|---|---|
TableViewDataSource |
UIKit table view handler |
CollectionViewDataSource |
UIKit collection view handler |
PaginationInfo |
Holds page info and hasMorePages |
ViewError |
Error with optional underlying reason |
EmptyStateConfiguration |
Custom empty view data (title, image, color) |
CellItemFactory |
Factory for table/collection cell items |
SupplementaryViewFactory |
Factory for header/footer views in collections |
- iOS 14.0+
- Swift 5.9+
- Xcode 15+
This package is released under the MIT License.
Feel free to open issues or submit pull requests! Feedback and contributions are welcome.
Designed by Ali Bamohammad with ❤️