mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-25 01:01:21 +01:00
Add descendantNodeRepresentingObject to Node.swift.
This commit is contained in:
parent
5888e1b7d0
commit
7ba2fe72dd
@ -114,17 +114,13 @@ public final class Node: Hashable {
|
||||
}
|
||||
|
||||
public func childNodeRepresentingObject(_ obj: AnyObject) -> Node? {
|
||||
|
||||
guard let childNodes = childNodes else {
|
||||
return nil
|
||||
}
|
||||
|
||||
for oneNode in childNodes {
|
||||
if oneNode.representedObject === obj {
|
||||
return oneNode
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
return findNodeRepresentingObject(obj, recursively: false)
|
||||
}
|
||||
|
||||
public func descendantNodeRepresentingObject(_ obj: AnyObject) -> Node? {
|
||||
|
||||
return findNodeRepresentingObject(obj, recursively: true)
|
||||
}
|
||||
|
||||
public func hasAncestor(in nodes: [Node]) -> Bool {
|
||||
@ -198,3 +194,23 @@ public extension Array where Element == Node {
|
||||
return self.map{ $0.representedObject }
|
||||
}
|
||||
}
|
||||
|
||||
private extension Node {
|
||||
|
||||
func findNodeRepresentingObject(_ obj: AnyObject, recursively: Bool = false) -> Node? {
|
||||
|
||||
guard let childNodes = childNodes else {
|
||||
return nil
|
||||
}
|
||||
for childNode in childNodes {
|
||||
if childNode.representedObject === obj {
|
||||
return childNode
|
||||
}
|
||||
if recursively, let foundNode = childNode.descendantNodeRepresentingObject(obj) {
|
||||
return foundNode
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user