Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stinger/76c71bda5f6daf8a21dfdd5c9cd6d50e to your computer and use it in GitHub Desktop.
Save stinger/76c71bda5f6daf8a21dfdd5c9cd6d50e to your computer and use it in GitHub Desktop.
RxCollectionViewSectionedAnimatedDataSource example with multiple cells types
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