[__NSCFCalendar components: fromDate: toDate: options:]: fromDate cannot be nil

I get this error. How to solve it. Please suggest me. Failure Report [__NSCFCalendar components: fromDate: toDate: options:]: fromDate cannot be nil I mean, really, what do you think the operation should mean with zero fromDate? Exception currently excluded. Some of these errors will be reported with this complaint, and then further violations are simply silent regardless of the random thing received from zero. Here is the back trace where this happened this time (some frames may be missing due to compiler optimization): My code

NSString *str_babyedays=aMileBusiness.str_DAte;
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"dd-MM-yyyy"];
    df.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"EN"];
    NSDate *titemdate = [df dateFromString: str_babyedays];



    NSDate *currentDate = [NSDate date];
    NSCalendar *gregorian = [[NSCalendar alloc]
                             initWithCalendarIdentifier:NSGregorianCalendar];
    NSUInteger unitFlags = NSMonthCalendarUnit | NSDayCalendarUnit;
    NSDateComponents *components = [gregorian components:unitFlags
                                                fromDate:titemdate
                                                  toDate:currentDate options:0];

    NSInteger months = [components month];
    NSInteger day= [components day];
-2
1

titemdate , NSDateFormatter str_babyedays. Apple NSDateFormatter:

dateFromString: , nil.

, , nil.

NSDateFormatter dateFromString conversion

NSDateFormatter dateFromString

dateFromString null dateformatter

+4

All Articles