DataDrivenRxDatasources - 基于 RxDataSources 的 MVVM 抽象样板代码。
使用数据源管理表格/集合视图的标准方法存在几个缺陷
RxDataSources 通过优雅的数据绑定机制和强大的 AnimatableSectionModel & SectionModel 抽象,帮助我们解决了一些问题,但在可重复的单元格注册和违反依赖倒置原则方面,仍然需要我们自己处理。
DataDrivenRxDatasources 带来了更高层次的抽象,让我们能够解决这些问题并设计一个数据驱动、可重用、声明式的表格/集合视图组件,该组件仅依赖于其 ViewModel。我们库的核心是基于抽象协议,这些协议应该提供绑定 Sections 和 Cells 的功能,但不关心这些 Sections 和 Cells 到底是什么。更多信息请参考 Medium
Swift Package Manager 通过 url: https://github.com/bigMOTOR/DataDrivenRxDatasources.git
Podfile: pod 'DataDrivenRxDatasources'
private typealias SectionViewModel = AnimatableTableSectionModel<String>
let cellItems = [
SampleCellViewModel(name: "Name 1"),
SampleCellViewModel(name: "Name 2")
]
let sections: Driver<[AnimatableTableSectionModel<String>]> = .just([SectionViewModel(model: "Some Section", items: cellItems)])
tableView.rx
.bind(sections: sections)
.disposed(by: bag)
请查看我们的 “Example” 项目以获取更多用例。
DataDrivenRxDatasources 需要 iOS11、RxDataSources 5.x 和 RxSwift 6.x。 对于最后一个 iOS10 支持,请使用 DataDrivenRxDatasources 2.1.0。 对于最后一个 RxSwift 5.x 支持,请使用 DataDrivenRxDatasources 1.2.0。
DataDrivenRxDatasources 在 MIT 许可证下可用。 有关更多信息,请参见 LICENSE 文件。