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/67bb633143ab5340328be8e9814c27e0 to your computer and use it in GitHub Desktop.
Save alobanov/67bb633143ab5340328be8e9814c27e0 to your computer and use it in GitHub Desktop.
Общий интерфейс компонентов. Composite
// уровень вложенности
enum CompoundItemLevel {
case root, section, item
}
protocol CompoundItemProtocol {
// уникальный идентификатор
var identifier: String {get}
// уровень на котором находится элемент
var level: CompoundItemLevel {get}
// список дочерних элементов элемента дерева
var children: [CompoundItemProtocol] {get}
// список элементов для работы
var items: [CompoundItemProtocol] {get}
// добавить дечерний элемент
func add(_ model: CompoundItemProtocol...)
// удалить дочерний элемент
func remove(_ model: CompoundItemProtocol)
}
// Возможность сравнивать объекты с протоколом CompoundItemProtocol
func == (lhs: CompoundItemProtocol, rhs: CompoundItemProtocol) -> Bool {
return lhs.identifier == rhs.identifier
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment