Skip to content

Instantly share code, notes, and snippets.

@alobanov
Last active November 3, 2017 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alobanov/6858458b24cadc7f7dce6ea6106e2222 to your computer and use it in GitHub Desktop.
Save alobanov/6858458b24cadc7f7dce6ea6106e2222 to your computer and use it in GitHub Desktop.
Базовая модель которая реализует общий протокол 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