I tried the same as you, setting
representedObject of the
ViewController to the
let viewController = windowController.contentViewController as! ViewController
viewController.representedObject = windowController.document
This almost works, the only problem is that, while using the RaiseMan app, if I close a document window, I get the following error on the debugger:
2017-04-26 19:12:14.828877-0300 RaiseMan[68170:1704702] [General] Cannot remove an observer <NSAutounbinderObservance 0x608000023180> for the key path "representedObject.employees" from <RaiseMan.ViewController 0x6080000c34f0>, most likely because the value for the key "representedObject" has changed without an appropriate KVO notification being sent. Check the KVO-compliance of the RaiseMan.ViewController class.
I’m assuming we shouldn’t set the representedObject to the
Document, but should instead set it to a model object like suggested in this Apple Q&A link: https://developer.apple.com/library/content/qa/qa1871/_index.html
Thinking of that, I also tried the following:
viewController.representedObject = employees
That works (also updating the ArrayController binding to just
representedObject instead of
representedObject.employees): I don’t get the debugger error and everything seems cool. However, it breaks down in chapter 11 because now I can’t override
removeValue() and such which are necessary for undo.
So I wonder, does anyone have a definitive solution for this?