AnimatableSectionModel.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // AnimatableSectionModel.swift
  3. // RxDataSources
  4. //
  5. // Created by Krunoslav Zaher on 1/10/16.
  6. // Copyright © 2016 Krunoslav Zaher. All rights reserved.
  7. //
  8. import Foundation
  9. public struct AnimatableSectionModel<Section: IdentifiableType, ItemType: IdentifiableType & Equatable> {
  10. public var model: Section
  11. public var items: [Item]
  12. public init(model: Section, items: [ItemType]) {
  13. self.model = model
  14. self.items = items
  15. }
  16. }
  17. extension AnimatableSectionModel
  18. : AnimatableSectionModelType {
  19. public typealias Item = ItemType
  20. public typealias Identity = Section.Identity
  21. public var identity: Section.Identity {
  22. return model.identity
  23. }
  24. public init(original: AnimatableSectionModel, items: [Item]) {
  25. self.model = original.model
  26. self.items = items
  27. }
  28. public var hashValue: Int {
  29. return self.model.identity.hashValue
  30. }
  31. }
  32. extension AnimatableSectionModel
  33. : CustomStringConvertible {
  34. public var description: String {
  35. return "HashableSectionModel(model: \"\(self.model)\", items: \(items))"
  36. }
  37. }
  38. extension AnimatableSectionModel
  39. : Equatable where Section: Equatable {
  40. public static func == (lhs: AnimatableSectionModel, rhs: AnimatableSectionModel) -> Bool {
  41. return lhs.model == rhs.model
  42. && lhs.items == rhs.items
  43. }
  44. }