How to add isLeaf and children to NSManagedObjects to use with a NSTreeController?

62 Views Asked by At

I am trying to use NSManagedObjects with an NSTreeController and NSOutlineView in my macOS app.

I have a two level data in the outline view: Project and Item, both are NSManagedObjects set up in my model.

In my storyboard, I added this:

enter image description here

enter image description here

And I added this in my code:

extension Project {
    @objc var isLeaf: Bool {
        return false
    }
    
    @objc var childCount: Int {
        return items?.count ?? 0
    }
    
    @objc var children: [Item] {
        return items?.allObjects as! [Item]
    }
}

extension Item {
    @objc var isLeaf: Bool {
        return true
    }
    
    @objc var childCount: Int {
        return 0
    }
    
    @objc var children: [NSManagedObject] {
        return []
    }
}

When I run the app, I get the following error:

Thread 1: "[<MyApp.ProjectBrowserViewController 0x600001580820> valueForUndefinedKey:]: this class is not key value coding-compliant for the key isLeaf."

It doesn't say which class but that error shows up twice, so I am guessing once for Project, and one for Item.

What am I missing here, how do I fix this? Will gladly add more info if needed.

0

There are 0 best solutions below