Section.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import UIKit
  15. /// Model object for a section in a tableview
  16. struct Section: Sectionable {
  17. var headerDescription: String?
  18. var footerDescription: String?
  19. var items: [Item]
  20. }
  21. /// Model object for a cell in a tableview section
  22. struct Item: Itemable {
  23. var title: String?
  24. var detailTitle: String?
  25. var textColor: UIColor?
  26. let isEditable: Bool
  27. var hasNestedContent: Bool
  28. var isChecked: Bool
  29. private var _image: UIImage?
  30. var image: UIImage? {
  31. get { _image ?? UIImage(named: title ?? "?") }
  32. set { _image = newValue }
  33. }
  34. init(title: String? = nil,
  35. detailTitle: String? = nil,
  36. textColor: UIColor? = .label,
  37. isEditable: Bool = false,
  38. hasNestedContent: Bool = false,
  39. isChecked: Bool = false,
  40. image: UIImage? = nil) {
  41. self.title = title
  42. self.detailTitle = detailTitle
  43. self.textColor = textColor
  44. self.isEditable = isEditable
  45. self.hasNestedContent = hasNestedContent
  46. self.isChecked = isChecked
  47. self.image = image
  48. }
  49. }