Reputation: 1387
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?
Upvotes: 0
Views: 436
Reputation: 930
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()
Upvotes: 4