Hi QuinceyMorris,
Actually, I do not find that your answer lines up with what I am experiencing.
I made a simple case project... I'll just post the code, it'll be quicker.
import Cocoa
class ViewController: NSViewController {
@objc dynamic var objs : [BKObj] = []
override func viewDidLoad() {
super.viewDidLoad()
/
objs = [BKBranch("one", [] ), BKObj("deadEnd"), BKBranch("second", [BKBranch("int", [BKObj("test"), BKObj("foo"), BKObj("tres")]), BKObj("sveldt"), BKObj("oop"), BKObj("pool")])]
}
override var representedObject: Any? {
didSet {
/
}
}
@IBAction func addStuff(sender: Any){
objs = [BKObj("replacement")]
}
}
class BKObj : NSObject{
@objc dynamic var isLeaf : Bool{
get {return true}
set{}
}
@objc dynamic var name : String = "name"
init(_ name: String) {
self.name = name
super.init()
}
}
class BKBranch : BKObj{
@objc dynamic var stuff : [BKObj] = []
@objc override dynamic var isLeaf : Bool{
get {return false}
set{}
}
@objc dynamic var count : Int {
get{
return stuff.count
}
set{}
}
init(_ name: String,_ stuff : [BKObj]) {
self.stuff = stuff
super.init(name)
}
}
so what you see is the VierwController for a mac osX desktop app, and the associated classes. BKBranch and BKObj are the classes that make up the herarchy. NOT specifically NSTreeNodes. you can see that in ViewDidLoad, I populate an array: objs with these objects.
there's an IBAction below that, that I trigger from a button in the ui.
it purposefully does the most blatant thing I could think of to upset the apple cart. a straight setting of the array's contents.
the xib is nothing to write home about. an NSTreeController, and an outlineView. the tree is bound to objs, and the outlineView is bound to the TreeController.
clicking the button, replaces the contents of the array. And the outlineView updates without complaint. Not what I was expecting, and not what I'd expect from your description.
maybe my 'stuff' property is KVO compliant enough. But if all it takes is to put @objc and dynamic in front of the property, then it's really no big deal, it's almost automatic.
but none of that is helping me solve my issues in my main app. All this tells me is that it's probably not anything to do with setting the contents of the array. I've checked to see that the Array exists,a nd that it gets populated, and that I can observe these changes. But for some reason I have not yet pinned down, my binding either from the TreeCon to the array, or from the outlineView to the TreeCon, just isn't working.