Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. protocol Modelable {
  2. var relatedCellIdentifier: String { get }
  3. }
  4.  
  5. protocol ConfigurableCell {
  6. func configure(with model: Modelable)
  7. }
  8.  
  9. // MARK: Models
  10.  
  11. struct Pomme: Modelable {
  12. let relatedCellIdentifier = String(describing: PommeCell.self)
  13. }
  14.  
  15. struct Abricot: Modelable {
  16. let relatedCellIdentifier = String(describing: AbricotCell.self)
  17. }
  18.  
  19. struct Banane: Modelable {
  20. let relatedCellIdentifier = String(describing: BananeCell.self)
  21. }
  22.  
  23. // MARK: Cells
  24.  
  25. final class PommeCell: UICollectionViewCell, ConfigurableCell {
  26.  
  27. override init(frame: CGRect) {
  28. super.init(frame: frame)
  29. addConstraints([
  30. widthAnchor.constraint(equalToConstant: 100),
  31. heightAnchor.constraint(equalToConstant: 50)
  32. ])
  33. }
  34.  
  35. required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
  36.  
  37. func configure(with model: Modelable) {
  38. backgroundColor = .green
  39. }
  40. }
  41.  
  42. final class AbricotCell: UICollectionViewCell, ConfigurableCell {
  43.  
  44. override init(frame: CGRect) {
  45. super.init(frame: frame)
  46. addConstraints([
  47. widthAnchor.constraint(equalToConstant: 50),
  48. heightAnchor.constraint(equalToConstant: 50)
  49. ])
  50. }
  51.  
  52. required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
  53.  
  54. func configure(with model: Modelable) {
  55. backgroundColor = .orange
  56. }
  57. }
  58.  
  59. final class BananeCell: UICollectionViewCell, ConfigurableCell {
  60.  
  61. override init(frame: CGRect) {
  62. super.init(frame: frame)
  63. addConstraints([
  64. widthAnchor.constraint(equalToConstant: 200),
  65. heightAnchor.constraint(equalToConstant: 50)
  66. ])
  67. }
  68.  
  69. required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
  70.  
  71. func configure(with model: Modelable) {
  72. backgroundColor = .yellow
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement