From 34563c3a2659cb3b8b699ebd5e5dbdfc7e977630 Mon Sep 17 00:00:00 2001 From: Maxim Bilan Date: Fri, 11 Jul 2014 15:54:03 +0300 Subject: [PATCH] Fixed 'Calendar Date Issue #2', posted by girishnair12345: "date cannot be nil..." --- ios_calendar/Sources/CalendarView.m | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ios_calendar/Sources/CalendarView.m b/ios_calendar/Sources/CalendarView.m index ecc3206..2501dad 100644 --- a/ios_calendar/Sources/CalendarView.m +++ b/ios_calendar/Sources/CalendarView.m @@ -214,11 +214,13 @@ - (void)setMode:(NSInteger)m - (void)setCurrentDate:(NSDate *)currentDate { - NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; - NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:currentDate]; - currentDay = [components day]; - currentMonth = [components month]; - currentYear = [components year]; + if (currentDate) { + NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; + NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:currentDate]; + currentDay = [components day]; + currentMonth = [components month]; + currentYear = [components year]; + } } - (NSDate *)currentDate