Created
March 28, 2017 09:53
-
-
Save stinger/76c71bda5f6daf8a21dfdd5c9cd6d50e to your computer and use it in GitHub Desktop.
RxCollectionViewSectionedAnimatedDataSource example with multiple cells types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment