NSPersistentDocument + StoryBoards: wrong for me wrong

I am trying to raise my head around StoryBoards for OS X - in particular, I am trying to write a document-based application using Core Data.

I cannot figure out how to provide the various View dispatchers in StoryBoard access to the NSPersistentDocument managedObjectController.

Prior to StoryBoards, if you create a document-based application using Core Data, you get a XIB file with a window owned by the document. The document has an array of window controllers, but the document was the owner of this XIB. You can add an NSArrayController, bind its managed entity context to the contents of the owner’s managed entities, and that's fine.

If instead you create a project using StoryBoards, then the top-level window belongs to NSWindowController. Where is the NSPsistentDocument located? It is created, but I do not see where and why.

Also, in this initial storyboard you get with a template, this window does not have an incoming arrow to say that it is an entry point. If you remove the window controller and add a new one, it has an arrow. AND NOW, you will have two TWO WINDOW CONTROLLERS - one that is made by a storyboard, and one that is made by a Document that creates it in the makeWindowControllers method

- (void)makeWindowControllers {
    // Override to return the Storyboard file name of the document.
    [self addWindowController:[[NSStoryboard storyboardWithName:@"Main" bundle:nil] instantiateControllerWithIdentifier:@"Document Window Controller"]];
}

This is mistake? It’s clear that I don’t understand something.

+4
source share
1 answer

. , , , , Apple . NSPersistentDocument makeWindowControllers() .

(windowController.window?.contentViewController as! MyViewController).moc = managedObjectContext

moc ( MyViewController), . . didSet , , .

, , viewDidLoad(), moc , , . .

, - .

+2

All Articles