title: Xcode: Invalid parameter not satisfying
body: <p>I keep running into a pretty frustrating error in Xcode after implementing a date picker. The error in the debugger is: "Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: date"</p>
  
  <p>I've been going through my code for hours now, and can't find the issue. It may be because I'm not checking for nil, there is no date the first time the app installs and launches, so that may be causing the crash. If it is, how do I check for nil in this code? I'm still very new at programming, any help would be much appreciated. Here is the code:</p>
  
  <pre><code>#import "DatePickerViewController.h"
  
  
  @implementation DatePickerViewController
  @synthesize datePicker;
  
  
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
      if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
      // Initialization code
      }
      return self;
  }
  
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
      // Return YES for supported orientations
      return (interfaceOrientation == UIInterfaceOrientationPortrait);
  }
  
  
  - (void)didReceiveMemoryWarning {
      [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
      // Release anything that's not essential, such as cached data
  }
  
  
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
      UILocalNotification *localNotif = [[UILocalNotification alloc] init];
  
      NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
      [dateFormatter setDateFormat:@"mm'/'dd'/'yyyy"];
  
      NSDate *eventDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"DatePickerViewController.selectedDate"];
  
      localNotif.fireDate = [eventDate dateByAddingTimeInterval:-13*60*60];
      localNotif.timeZone = [NSTimeZone defaultTimeZone];
  
  
      localNotif.alertBody = @"Tomorrow!";
  
      localNotif.alertAction = nil;
  
      localNotif.soundName = UILocalNotificationDefaultSoundName;
      localNotif.applicationIconBadgeNumber = 0;
      [[UIApplication sharedApplication]presentLocalNotificationNow:localNotif];    
  
      return YES;
  }
  
  
  - (void)viewDidLoad {
      NSDate *storedDate = [[NSUserDefaults standardUserDefaults] 
                    objectForKey:@"DatePickerViewController.selectedDate"];
  
      [self.datePicker setDate:storedDate animated:NO];
  }
  
  - (IBAction)dateChanged:(id)sender {
      NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  
      NSDate *selectedDate = [self.datePicker date];
  
      [defaults setObject:selectedDate forKey:@"DatePickerViewController.selectedDate"];
  }
  </code></pre>