Expand item in NSOutlineView with NSTreeController

131 views Asked by At

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

1

There are 1 answers

0
Willeke On BEST ANSWER

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 {
    …
}