title: "window" undeclared (first use in this function) error in iOS tutorial
body: <p>I am trying the Core Data Tutorial and I have copied the code as given in this Apple's tutorial on Core Data here:</p>
  
  <p><a href="http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/iPhoneCoreData01/Articles/02_RootViewController.html" rel="nofollow">http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/iPhoneCoreData01/Articles/02_RootViewController.html</a></p>
  
  <p>It asks us to compile and run after implementing the application delegate. When I do so, Xcode 4 compiler gives this error "window undeclared (first use in this function)". I can see that there is window declared as a property and there is a synthesize line in the code like so:</p>
  
  <p>@synthesize window=_window;</p>
  
  <p>so even though there is a window property declared in the program, why am I getting this error?</p>
  
  <p>Here are the .h and .m files:</p>
  
  <p>.h:
      #import </p>
  
  <pre><code>@interface LocationsAppDelegate : NSObject &lt;UIApplicationDelegate&gt; {
      UINavigationController *navigationController;
  
  }
  
  @property (nonatomic, retain) IBOutlet UIWindow *window;
  @property (nonatomic, retain) UINavigationController *navigationController;
  
  @property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
  @property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
  @property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
  
  - (void)saveContext;
  - (NSURL *)applicationDocumentsDirectory;
  
  @end
  </code></pre>
  
  <p>Now for the .m file:</p>
  
  <pre><code>#import "LocationsAppDelegate.h"
  #import "RootViewController.h"
  
  @implementation LocationsAppDelegate
  
  @synthesize navigationController;
  
  @synthesize window=_window;
  
  @synthesize managedObjectContext=__managedObjectContext;
  
  @synthesize managedObjectModel=__managedObjectModel;
  
  @synthesize persistentStoreCoordinator=__persistentStoreCoordinator;
  
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
  
      RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
  
      NSManagedObjectContext *context = [self managedObjectContext];
      if(!context) {
          //handle the error you dummy!!
      }
  
      rootViewController.managedObjectContext = context;
  
  
      UINavigationController *aNavigationController = [[UINavigationController alloc]initWithRootViewController:rootViewController];
      self.navigationController = aNavigationController;
  
  
      [self.window addSubview:[navigationController view]];
      [self.window makeKeyAndVisible];
  
       [rootViewController release];
   [aNavigationController release];
  
  
      return YES;
  }
  
  
  - (void)applicationWillTerminate:(UIApplication *)application
  {
      [self saveContext];
  }
  
  - (void)dealloc
  {
      [_window release];
      [__managedObjectContext release];
      [__managedObjectModel release];
      [__persistentStoreCoordinator release];
      [super dealloc];
  }
  
  - (void)saveContext
  {
      NSError *error = nil;
      NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
      if (managedObjectContext != nil)
      {
          if ([managedObjectContext hasChanges] &amp;&amp; ![managedObjectContext save:&amp;error])
          {
  
              NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
              abort();
          } 
      }
  }
  
  #pragma mark - Core Data stack
  
  - (NSManagedObjectContext *)managedObjectContext
  {
      if (__managedObjectContext != nil)
      {
          return __managedObjectContext;
      }
  
      NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
      if (coordinator != nil)
      {
          __managedObjectContext = [[NSManagedObjectContext alloc] init];
          [__managedObjectContext setPersistentStoreCoordinator:coordinator];
      }
      return __managedObjectContext;
  }
  
  - (NSManagedObjectModel *)managedObjectModel
  {
      if (__managedObjectModel != nil)
      {
          return __managedObjectModel;
      }
      NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Locations" withExtension:@"momd"];
      __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];    
      return __managedObjectModel;
  }
  
  - (NSPersistentStoreCoordinator *)persistentStoreCoordinator
  {
      if (__persistentStoreCoordinator != nil)
      {
          return __persistentStoreCoordinator;
      }
  
      NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Locations.sqlite"];
  
      NSError *error = nil;
      __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
      if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&amp;error])
      {
  
          NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
          abort();
      }    
  
      return __persistentStoreCoordinator;
  }
  
  #pragma mark - Application's Documents directory
  
  - (NSURL *)applicationDocumentsDirectory
  {
      return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
  }
  
  @end
  </code></pre>