title: Set representedObject on an NSViewController in a document-based OS X application
body: <p>I am working on a simple OS X Cocoa application, in which the user fills in a form and the application performs some calculations that pop up in other fields.</p>
  
  <p>I started with the default Document-Based Application template on Xcode 6.3.2 (for Yosemite). This template includes a subclass of NSDocument and a subclass of NSViewController. The interface is defined in a Storyboard. The NSDocument initializes the interface from the Storyboard in makeWindowControllers.</p>
  
  <p>I ran into trouble binding pieces of the interface to the ViewController's representedObject -- it turned out I was binding to nil. The ViewController's setRepresentedObject method is never called.</p>
  
  <p>I tried having the ViewController call setRepresentedObject on itself in viewDidLoad, but the WindowController's document property hadn't been set at that point (it returned nil).</p>
  
  <p>And it's not clear to me if it's possible to get an instance of the ViewController from the NSDocument - the NSDocument knows about its window/WindowController, but I'm not sure how to find a ViewController from those classes.</p>
  
  <p><strong>I want to know the idiomatic Xcode/Apple way to do this. Whether that is via the Storyboard view or programmatically in my code.</strong></p>
  
  <p>I would also like to avoid coupling the code too tightly, if possible.</p>