I am currently fighting with NSDocument in a document based Storyboard based Cocoa Application (Objective C). Can anybody tell me how i can access the document in the NSViewCon
This does not directly address the question. But the Q&A link below shows how to access the data model in your document from NSControl objects using bindings, by utilising the preparedObject of the NSViewController.
https://developer.apple.com/library/content/qa/qa1871/_index.html
I set the representedObject for the NSViewController in Document.m as following:
- (void)makeWindowControllers {
NSWindowController* wc = [[NSStoryboard storyboardWithName:@"Main" bundle:nil] instantiateControllerWithIdentifier:@"Document Window Controller"];
NSViewController* vc = wc.contentViewController;
vc.representedObject = self.model;
[self addWindowController:wc];
}
Now representedObject of my ViewController is set to model. Assuming my model has a text property, I can bind any NSControl to that property through ViewController with keyPath: self.representedObject.text