swiftobjective-cnsoutlineviewnstreecontroller

Expand item in NSOutlineView with NSTreeController


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


Solution

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