Skip to content

Instantly share code, notes, and snippets.

@mateuszszklarek
Last active February 1, 2019 18:28
Show Gist options
  • Save mateuszszklarek/4b21f6fcfdba7bb4db3d546dc2e8fe66 to your computer and use it in GitHub Desktop.
Save mateuszszklarek/4b21f6fcfdba7bb4db3d546dc2e8fe66 to your computer and use it in GitHub Desktop.
#!/usr/bin/swift
class Node {
var children: [Node] = []
var depth: Int = 0 {
didSet {
for child in children {
child.depth = depth + 1
}
}
}
}
let node = Node()
let child = Node()
let grandchild = Node()
node.children.append(child)
child.children.append(grandchild)
node.depth = 1
print("Node: \(node.depth)")
print("Child: \(child.depth)")
print("Grandchild: \(grandchild.depth)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment