title: Where is your Application Delegate set and who initializes its window and viewController properties?
body: <p>I have a very newbie question about IOS apps... If I create a new View Based Application called TestForStackOverflow, Xcode automatically creates code like this for the TestForStackOverflowAppDelegate.h:</p>
  
  <pre><code>@class TestForStackOverflowViewController;
  
  @interface TestForStackOverflowAppDelegate : NSObject &lt;UIApplicationDelegate&gt;
  
  @property (nonatomic, retain) IBOutlet UIWindow *window;
  
  @property (nonatomic, retain) IBOutlet TestForStackOverflowViewController *viewController;
  
  @end
  </code></pre>
  
  <p>and the following in TestForStackOverflowAppDelegate.m:</p>
  
  <pre><code>#import "TestForStackOverflowAppDelegate.h"
  
  #import "TestForStackOverflowViewController.h"
  
  @implementation TestForStackOverflowAppDelegate
  
  @synthesize window = _window;
  @synthesize viewController = _viewController;
  
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
      // Override point for customization after application launch.
  
      self.window.rootViewController = self.viewController;
      [self.window makeKeyAndVisible];
      return YES;
  }
  
  [...]
  </code></pre>
  
  <p>Here come my questions:</p>
  
  <p>1) where is the TestForStackOverflowAppDelegate class set as delegate for the current application? Is it done "automagically"? I've seen that the main.m source file contains only
  the following code:</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
      int retVal = UIApplicationMain(argc, argv, nil, nil);
      [pool release];
      return retVal;
  }
  </code></pre>
  
  <p>Shouldn't it set the application delegate class in the fourth parameter of the UIApplicationMain function invocation?</p>
  
  <p>2) where are the window and viewController properties of TestForStackOverflowAppDelegate class being set? </p>
  
  <p>3) this may be trivial, but why do we have synthesize window = _window, without having an instance variable called _window in TestForStackOverflowAppDelegate interface? I've seen that you can declare @properties without having the corresponding iVars in the class interfaces (maybe they are automatically created by the compiler), but is it a good practice or should you always create the corresponding iVars in your classes?</p>
  
  <p>Excuse me for the very long message, I just hope I've not written a too obvious question since here in Italy is late night and I'm very tired.. but when these questions come into my head, I can't wait for the solution :)</p>