Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. import UIKit
  2. import RxSwift
  3. import RxCocoa
  4. import RxDataSources
  5.  
  6. class ViewController: BaseCollectionViewController {
  7.  
  8. ...
  9.  
  10. typealias Section = AnimatableSectionModel<String, CellStyle>
  11. private let dataSource = RxCollectionViewSectionedAnimatedDataSource<Section>()
  12.  
  13. ...
  14.  
  15. override func viewDidLoad() {
  16. super.viewDidLoad()
  17.  
  18. ...
  19.  
  20. ...
  21. .map { [Section(model: "", items: $0.map(CellStyle.link))] }
  22. .asDriver(onErrorDriveWith: .empty())
  23. .drive(collectionView.rx.items(dataSource: dataSource))
  24. .disposed(by: disposeBag)
  25.  
  26. dataSource.configureCell = { (dataSource, collectionView, indexPath, cellStyle) in
  27. switch cellStyle {
  28. case let .link(link):
  29. let cell = GiftCollectionViewCell.dequeue(from: collectionView, forIndexPath: indexPath)
  30. cell.link = link
  31. return cell
  32. }
  33. }
  34. }
  35.  
  36. enum CellStyle {
  37. case link(Link)
  38. }
  39. }
  40.  
  41. extension ViewController.CellStyle: IdentifiableType, Equatable {
  42. var identity: String {
  43. switch self {
  44. case let .link(link):
  45. return link.identifier
  46. }
  47. }
  48.  
  49. public static func ==(lhs: ViewController.CellStyle, rhs: ViewController.CellStyle) -> Bool {
  50. return false
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement