Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Базовая модель которая реализует общий протокол CompoundItemProtocol
class BaseCompoundItem: CompoundItemProtocol {
var children: [CompoundItemProtocol] = []
let level: CompoundItemLevel
let identifier: String
var items: [CompoundItemProtocol] {
return children
}
// инициализация без параметров создает рутовый элемент структуры
init() {
self.identifier = "root"
self.level = .root
}
init(identifier: String, level: CompoundItemLevel) {
self.identifier = identifier
self.level = level
}
func add(_ model: CompoundItemProtocol...) {
self.children.append(contentsOf: model)
}
func remove(_ model: CompoundItemProtocol) {
if let index = self.children.index(where: { $0 == model }) {
children.remove(at: index)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.