0

I'm trying (unsuccessfully) to get the node from a disclosure button clicked

I think this function is the more appropriate:

func outlineViewItemDidExpand(_ notification: Notification) {
     
     let nodeToExpand = notification.userInfo as! Node
     let nodeToExpand2 = notification.userInfo["NSObject"] as! Node

    //Error @selector(_outlineControlClicked:) from sender NSButton 0x10053d710

}

enter image description here

  • Do you want to expand the node from code or do you want to be notified when the user expands the node? – Willeke Sep 25 '21 at 07:53
  • I need to get the URL assigned to this node (Node.url) in order to append childrenNode to his parentNode. –  Sep 25 '21 at 10:20
  • What is preventing you from getting the URL from `nodeToExpand2`? – Willeke Sep 25 '21 at 10:54
  • This is the error message when I try code upper : --> "Could not cast value of type 'NSKVONotifying_NSTreeControllerTreeNode' (0x600003018b40) to 'Editor.Node' (0x100040720). Performing @selector(_outlineControlClicked:) from sender NSButton 0x100649c90" –  Sep 25 '21 at 11:24

1 Answers1

0

NSTreeController wraps your nodes in NSTreeNode objects. Your node is representedObject of the NSTreeNode.

if let treeNode = notification.userInfo["NSObject"] as? NSTreeNode,
   let node = treeNode.representedObject as? Node {
    …
}
Willeke
  • 14,578
  • 4
  • 19
  • 47