Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import RxSwift
- import RxCocoa
- import RxDataSources
- class ViewController: BaseCollectionViewController {
- ...
- typealias Section = AnimatableSectionModel<String, CellStyle>
- private let dataSource = RxCollectionViewSectionedAnimatedDataSource<Section>()
- ...
- override func viewDidLoad() {
- super.viewDidLoad()
- ...
- ...
- .map { [Section(model: "", items: $0.map(CellStyle.link))] }
- .asDriver(onErrorDriveWith: .empty())
- .drive(collectionView.rx.items(dataSource: dataSource))
- .disposed(by: disposeBag)
- dataSource.configureCell = { (dataSource, collectionView, indexPath, cellStyle) in
- switch cellStyle {
- case let .link(link):
- let cell = GiftCollectionViewCell.dequeue(from: collectionView, forIndexPath: indexPath)
- cell.link = link
- return cell
- }
- }
- }
- enum CellStyle {
- case link(Link)
- }
- }
- extension ViewController.CellStyle: IdentifiableType, Equatable {
- var identity: String {
- switch self {
- case let .link(link):
- return link.identifier
- }
- }
- public static func ==(lhs: ViewController.CellStyle, rhs: ViewController.CellStyle) -> Bool {
- return false
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement