Last active
November 3, 2017 14:15
-
-
Save alobanov/11e1e95eba62aa4e70857fcebe0d96ca to your computer and use it in GitHub Desktop.
Модель ячейки
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Сделаем нашей модели read only протокол, только с необходимыми полями | |
| protocol CellCompoundItemProtocol { | |
| var title: String? {get} | |
| var subtitle: String? {get} | |
| var cellIdentifier: String {get} | |
| } | |
| class CellCompoundItem: CompoundItemProtocol, CellCompoundItemProtocol { | |
| private let decoratedComposite: CompoundItemProtocol | |
| var title: String? | |
| var subtitle: String? | |
| let cellIdentifier: String | |
| var identifier: String { | |
| return self.decoratedComposite.identifier | |
| } | |
| // это лист дерева так что возвращаем самого себя | |
| var tems: [CompoundItemProtocol] { | |
| return [self] | |
| } | |
| // детей у листов быть не может | |
| var children: [CompoundItemProtocol] { | |
| return [] | |
| } | |
| var level: CompoundItemLevel { | |
| return self.decoratedComposite.level | |
| } | |
| init(identifier: String, cellIdentifier: String, title: String?, subtitle: String?) { | |
| self.decoratedComposite = BaseCompoundItem(identifier: identifier, level: .item) | |
| self.title = title | |
| self.subtitle = subtitle | |
| self.cellIdentifier = cellIdentifier | |
| } | |
| func add(_ model: CompoundItemProtocol...) { | |
| print("Нельзя добавить дочерние элементов, этот элемент является листом структуры") | |
| } | |
| func remove(_ model: CompoundItemProtocol) { | |
| print("У листьев нет детей, нечего удалять") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment