Make Node.childNodes non-optional.
This commit is contained in:
parent
7def2ae8d0
commit
6e6eefab27
@ -16,7 +16,7 @@ public final class Node: Hashable {
|
|||||||
public let representedObject: AnyObject
|
public let representedObject: AnyObject
|
||||||
public var canHaveChildNodes = false
|
public var canHaveChildNodes = false
|
||||||
public var isGroupItem = false
|
public var isGroupItem = false
|
||||||
public var childNodes: [Node]?
|
public var childNodes = [Node]()
|
||||||
public let hashValue: Int
|
public let hashValue: Int
|
||||||
private static var incrementingID = 0
|
private static var incrementingID = 0
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ public final class Node: Hashable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public var numberOfChildNodes: Int {
|
public var numberOfChildNodes: Int {
|
||||||
return childNodes?.count ?? 0
|
return childNodes.count
|
||||||
}
|
}
|
||||||
|
|
||||||
public var indexPath: IndexPath {
|
public var indexPath: IndexPath {
|
||||||
@ -87,9 +87,6 @@ public final class Node: Hashable {
|
|||||||
|
|
||||||
public func childAtIndex(_ index: Int) -> Node? {
|
public func childAtIndex(_ index: Int) -> Node? {
|
||||||
|
|
||||||
guard let childNodes = childNodes else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if index >= childNodes.count || index < 0 {
|
if index >= childNodes.count || index < 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -98,7 +95,7 @@ public final class Node: Hashable {
|
|||||||
|
|
||||||
public func indexOfChild(_ node: Node) -> Int? {
|
public func indexOfChild(_ node: Node) -> Int? {
|
||||||
|
|
||||||
return childNodes?.index{ (oneChildNode) -> Bool in
|
return childNodes.index{ (oneChildNode) -> Bool in
|
||||||
oneChildNode === node
|
oneChildNode === node
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -189,9 +186,6 @@ private extension Node {
|
|||||||
|
|
||||||
func findNodeRepresentingObject(_ obj: AnyObject, recursively: Bool = false) -> Node? {
|
func findNodeRepresentingObject(_ obj: AnyObject, recursively: Bool = false) -> Node? {
|
||||||
|
|
||||||
guard let childNodes = childNodes else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
for childNode in childNodes {
|
for childNode in childNodes {
|
||||||
if childNode.representedObject === obj {
|
if childNode.representedObject === obj {
|
||||||
return childNode
|
return childNode
|
||||||
|
@ -53,8 +53,8 @@ public final class TreeController {
|
|||||||
return oneNode
|
return oneNode
|
||||||
}
|
}
|
||||||
|
|
||||||
if recurse, oneNode.canHaveChildNodes, let childNodes = oneNode.childNodes {
|
if recurse, oneNode.canHaveChildNodes {
|
||||||
if let foundNode = nodeInArrayRepresentingObject(nodes: childNodes, representedObject: representedObject, recurse: recurse) {
|
if let foundNode = nodeInArrayRepresentingObject(nodes: oneNode.childNodes, representedObject: representedObject, recurse: recurse) {
|
||||||
return foundNode
|
return foundNode
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ private extension TreeController {
|
|||||||
func visitNode(_ node: Node, _ visitBlock: NodeVisitBlock) {
|
func visitNode(_ node: Node, _ visitBlock: NodeVisitBlock) {
|
||||||
|
|
||||||
visitBlock(node)
|
visitBlock(node)
|
||||||
node.childNodes?.forEach{ (oneChildNode) in
|
node.childNodes.forEach{ (oneChildNode) in
|
||||||
visitNode(oneChildNode, visitBlock)
|
visitNode(oneChildNode, visitBlock)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,14 +117,14 @@ private extension TreeController {
|
|||||||
|
|
||||||
var childNodesDidChange = false
|
var childNodesDidChange = false
|
||||||
|
|
||||||
let childNodes = delegate?.treeController(treeController: self, childNodesFor: node)
|
let childNodes = delegate?.treeController(treeController: self, childNodesFor: node) ?? [Node]()
|
||||||
|
|
||||||
childNodesDidChange = !nodeArraysAreEqual(childNodes, node.childNodes)
|
childNodesDidChange = !nodeArraysAreEqual(childNodes, node.childNodes)
|
||||||
if (childNodesDidChange) {
|
if (childNodesDidChange) {
|
||||||
node.childNodes = childNodes
|
node.childNodes = childNodes
|
||||||
}
|
}
|
||||||
|
|
||||||
childNodes?.forEach{ (oneChildNode) in
|
childNodes.forEach{ (oneChildNode) in
|
||||||
if rebuildChildNodes(node: oneChildNode) {
|
if rebuildChildNodes(node: oneChildNode) {
|
||||||
childNodesDidChange = true
|
childNodesDidChange = true
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user