Search code examples
swiftstoryboardosx-yosemitensdocument

passing document data to the view controllers in yosemite (storyboards)


When are you supposed to pass your document or document data to your viewcontrollers? It can not be done in prepareForSegue because this function is not called for view controllers that are part of a containment/relationship seque.

Also not in windowControllerDidLoadNib because this is not always called either.


Solution

  • My current approach is this:

    1. Subclass NSDocument and override makeWindowControllers to pass the document instance to the window controller.
    2. Subclass NSWindowController and override windowDidLoad to pass the document (or any other type of data) to the contentViewController.
    3. Subclass the NSViewController to handle the data and/or pass it along to childViewControllers.

    4. Use notifications to notify NSViewControllers if something (like the selection) has changed in another NSViewController.