Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crash with DatePicker and NSDate

I have mysterious crash when trying to launch my app on iPhone (it perfectly valid works on Simulator though). I think problem is in this 2 methods..:

-(void)viewWillAppear:(BOOL)animated{
    [self getValueFromPicker];
}


-(void)getValueFromPicker{

    NSDate *now = [NSDate date];

    NSDate *birthDate = self.birthdayPicker.date;

    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit
                                               fromDate:now
                                                 toDate:birthDate
                                                options:0];

    NSLog(@"Difference in years %i/", components.year);

}

App crash with SIGABRT error, and there is a text i can see in a console: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: date'

Please help me, i'am really have no idea what i did wrong, when i did the same thing on Simulator in console i can see difference in years from Now date and date, user picked.

Update:after i removed [self defaultBirthdayPickerDate]; in viewDidLoad section it start to work. But, now picker show current date, its not very convenient for picking birthday Date, now i still need to change its current date from now to past..

like image 313
Evgeniy Kleban Avatar asked Dec 27 '22 08:12

Evgeniy Kleban


1 Answers

Mostly this types of error generated when you applies nil date: check values of self.birthdayPicker.date it is nil or/not ?? and give proper condition if you get nil value of UIDatePicker.

like image 159
iPatel Avatar answered Jan 13 '23 00:01

iPatel