Steven Lord
Steven Lord

Reputation: 263

Setting TreeController childrenKeyPath throwing error

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 ?

Upvotes: 0

Views: 197

Answers (0)

Related Questions