I have been following this tutorial. I’m having conceptual trouble at the point where an App Controller class is written, and then added and hooked up within Interface Builder.
Adding the AppController Class
The next task is to add an instance of the
new class to the Interface Builder
document and connect the class
outlets.Create an instance of the
AppController class. In the Interface
Builder Library window, click Classes.
Locate the AppController class. Drag
this class into the document window to
create an instance named App
Controller. Connect the App
Controller’s qcWindow outlet to the
design window. Hold down the Control
key. In the document window, drag from
the App Controller to the Window
object. Select the qcWindow outlet
from the list that appears. Connect
the App Controller’s qcView outlet to
the QC view in the design window. Hold
down the Control key. Drag from the
App Controller to the QC view in the
design window. Select the qcView
outlet from the list that appears.
Specifically, I don’t understand how this App Controller is being used at run-time. All I did was hook up the window and view outlets within IB, and it magically works as if it was being initialized within the applicationDidFinishLaunching:aNotification method of my app delegate. My point is, I’m not using my App Controller class anywhere in my code, and all I’ve done in IB is hook up its outlets, so how does it work?
When your application is launched, a shared instance of NSApplication is created and MainMenu.xib/nib is loaded and its contents (including the main menu itself) are hooked up. During this loading processs, the NSApp instance’s delegate is pointed at your “un-freeze-dried” (unarchived) class, which (among other possible things) can answer NSApp delegate questions and can then begin messaging it (and relying on it for App-wide behavioral customizations).
One useful aspect of all this is that you can access the delegate from anywhere in your app via
[NSApp delegate], which is short for[[NSApplication sharedApplication] delegate]. This is extremely handy for navigating parts of your architecture if you hang them off your app delegate and provide accessors for them (like[[NSApp delegate] fooController]).