If I create a New Project in xcode, then choose “View-based Application”, the delegate and view controller class templates are generated automatically. Here’s a snippet from DummyAppDelegate.h
@class dummyViewController;
@interface dummyAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
dummyViewController *viewController;
}
My main question is: where is instance variable viewController instantiated? I can see no code for this in the generated files, so is some connection in InterfaceBuilder instantiating it automatically?
A second, lesser question is why @class is used in the code above rather than a simple
#include "dummyViewController.h"
Any help is much appreciated, many thanks!
The window, the view controller, and also the application delegate are all loaded from
MainWindow.xib. Any object you place in a NIB file gets instantiated once that NIB file is loaded. And by specifying MainWindow.nib in the app’s Info.plist, you tell Cocoa (actually, theUIApplicationinstance) to automatically load that file on app startup.The
@class ...statement is a so-called forward declaration. It is considered good programming practice because its use can shorten compile times (the fewer header files you need import, the faster the compile step is).