Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protocol Modelable {
- var relatedCellIdentifier: String { get }
- }
- protocol ConfigurableCell {
- func configure(with model: Modelable)
- }
- // MARK: Models
- struct Pomme: Modelable {
- let relatedCellIdentifier = String(describing: PommeCell.self)
- }
- struct Abricot: Modelable {
- let relatedCellIdentifier = String(describing: AbricotCell.self)
- }
- struct Banane: Modelable {
- let relatedCellIdentifier = String(describing: BananeCell.self)
- }
- // MARK: Cells
- final class PommeCell: UICollectionViewCell, ConfigurableCell {
- override init(frame: CGRect) {
- super.init(frame: frame)
- addConstraints([
- widthAnchor.constraint(equalToConstant: 100),
- heightAnchor.constraint(equalToConstant: 50)
- ])
- }
- required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
- func configure(with model: Modelable) {
- backgroundColor = .green
- }
- }
- final class AbricotCell: UICollectionViewCell, ConfigurableCell {
- override init(frame: CGRect) {
- super.init(frame: frame)
- addConstraints([
- widthAnchor.constraint(equalToConstant: 50),
- heightAnchor.constraint(equalToConstant: 50)
- ])
- }
- required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
- func configure(with model: Modelable) {
- backgroundColor = .orange
- }
- }
- final class BananeCell: UICollectionViewCell, ConfigurableCell {
- override init(frame: CGRect) {
- super.init(frame: frame)
- addConstraints([
- widthAnchor.constraint(equalToConstant: 200),
- heightAnchor.constraint(equalToConstant: 50)
- ])
- }
- required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
- func configure(with model: Modelable) {
- backgroundColor = .yellow
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement