My NSTreeController is setting Core Data parent attributes but not children attributes.
I have a Core Data model like this
Item
title (string)
isLeaf (boolean,readonly)
parent -> Group (inverse children)
Group (parent entity Item)
children -> Item (inverse parent)
Leaf (parent entity Item)
I am then displaying it with NSOutlineView and using an NSTreeController. I use the method -[NSTreeController insertObject:atArrangedObjectIndexPath:] to try to insert Leaf’s, the leafs parent property is set correctly but the parent Group.children property remains set to nil.
When I run the project I get the following warning on the console
Warning: <NSTreeController: 0x7fcd93c19d20>[object class: NSMutableDictionary] childrenKeyPath cannot be nil. To eliminate this log message, set the childrenKeyPath attribute in Interface Builder
even though childrenKeyPath is set in interface builder and why is it using NSMutableDictionary when I have a NSManagedObject subclasses SavedItem, SavedGroup and SavedLeaf. I have downloaded a couple of examples but I can not see what they are doing that I am not.
The solution for others, is I was trying to be clever and instead of defining the isLeaf property in the actual core data definition. I was try to hard code it in the implementation as returning true or false depending on whether it was Group or Leaf, for some reason NSTreeController does not like this, even if you also define it in the base class. I have overridden the awakeFromInsert method and set it there.
Also of interest is that NSTreeController also does not like it if you define the children property in the base class to do nothing/return nil (ie so the the Group subclass can override it), children entities will be saved but they will no be displayed. This is something I did in trying to solve my initial problem, I thought it was something people might like to know.