SectionModel.swift 1.1 KB

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