Getting NSDocumentController from NSDocument

405 Views Asked by At

I have subclassed both NSDocumentController and NSDocument. Is there a way to get to the MyDocumentController from MyDocument?

Currently I have an outlet in my AppDelegate that connects to MyDocumentController, so I can get to it that way, but was wondering if there was a more directly accepted way?

1

There are 1 best solutions below

0
Bob On BEST ANSWER

You don't need an outlet or anything like that. NSDocumentController is a singleton, meaning that there's only ever one instance that manages documents for the whole app. Because you have that custom document controller in your nib, it's the first to be instantiated and therefore becomes the shared document controller. So all you have to do is retrieve the shared document controller:

In Objective-C:

MyDocumentController *sharedController = [MyDocumentController sharedDocumentController];

In Swift:

let sharedController = MyDocumentController.shared()