0

I am trying to set up an NSOutlineView using a TreeController.

I have the following class for each node in the tree:

@objc class EdLevel: NSObject{

    @objc dynamic var isLeaf: Bool { return children.count == 0}
    @objc dynamic var childCount: Int { return children.count}
    @objc dynamic var children: [EdLevel] = []

    @objc dynamic var name: String

    @objc init(name n: String){
        name = n
    }
}

In my Xcode story board I have done the following settings: Tree Controller key paths

Tree controller content array

I currently have the following property in my view controller (called Admin in IB)

@objc dynamic var eddingtonNumberLevels: [EdLevel] = []

When I run this I get an exception at my AppDelegate with no information about where it failed. I get the same thing if I remove the “Count” and “Leaf” Key paths (which I understand to be optional anyway as they can be derived from “Children”]. When I remove the Children key path it all runs (with no content of course) but I get “childrenKeyPath cannot be nil. To eliminate this log message, set the childrenKeyPath attribute in Interface Builder”

I’ve searched for answers but they all just say set the childrenKeyPath with explaining what form that property should take. I’ve tried changing children to be an NSArray but that didn’t help.

Any suggestions on what the problem ?

Steven Lord
  • 253
  • 4
  • 15
  • The exception could be caused by anything after the childrenKeyPath is used. See [Xcode exception breakpoint doesn't print details of the exception being thrown](https://stackoverflow.com/questions/17238673/xcode-exception-breakpoint-doesnt-print-details-of-the-exception-being-thrown) or Google "swift debug exception". – Willeke Feb 01 '18 at 11:22
  • good point! That link looks like a wealth of information. I should get a chance to look through it later today. Thank you. – Steven Lord Feb 01 '18 at 12:00
  • by sheer fluke I solved it. I had to bind the first column of my NSOutlineView to the TreeControllers arranged objects. I had been binding the whole NSOutlineView. Is the correct approach for me to add this as the answer to my own question ? – Steven Lord Feb 03 '18 at 11:46
  • This is the correct approach if the outline view is cell based. Nowadays a view based outline view is recommended. – Willeke Feb 03 '18 at 12:05
  • thanks. I will shift to view based then. – Steven Lord Feb 03 '18 at 12:06

0 Answers0