title: UIApplication sharedApplication - keyWindow is nil?
body: <p>I want to convert a CGPoint from my UIView to UIWindow coordinates and have realized that  UIApplication keyWindow is always nil; why is this?</p>
  
  <p>I have tried the <code>convertPoint:toView:</code> method from UIView.</p>
  
  <p>Please see this sample code I tried in the view controller in a template of Xcode (View application):</p>
  
  <pre><code>- (void)viewDidLoad {
      [super viewDidLoad];
      UIView *test =  [[UIView alloc] initWithFrame:CGRectMake(40,40,250,250)];
      [test setBackgroundColor:[UIColor redColor]];
      [self.view addSubview:test];
  
      CGPoint p = CGPointMake(100, 100);
      CGPoint np;
  
      np = [test convertPoint:p toView:[[UIApplication sharedApplication] keyWindow]];
      NSLog(@"p:%@ np:%@", NSStringFromCGPoint(p), NSStringFromCGPoint(np));
  
      AppDelegate *appDel =  (AppDelegate *)[UIApplication sharedApplication].delegate;
  
      np = [test convertPoint:p toView:[appDel window]];
      NSLog(@"p:%@ np:%@", NSStringFromCGPoint(p), NSStringFromCGPoint(np));
  
      np = [test convertPoint:p toView:nil];
      NSLog(@"p:%@ np:%@", NSStringFromCGPoint(p), NSStringFromCGPoint(np));
  
      [test release];
  
      if(![[UIApplication sharedApplication] keyWindow])
          NSLog(@"window was nil");
  }
  </code></pre>
  
  <p>and I get:</p>
  
  <pre><code>p:{100, 100} np:{100, 100}
  p:{100, 100} np:{140, 160}
  p:{100, 100} np:{100, 100}
  window was nil
  </code></pre>
  
  <p>I can convert it but only when I access the window through the app delegate. And not UIApplication. According to the documentation, keyWindow should work here, but is nil.
  Why is this?</p>