执行以下代码后
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *expiryDateComponents = [calendar components:(NSCalendarUnitEra|NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay) fromDate:aDate];
你得到以下非崩溃异常
*** -[__NSCFCalendar dateFromComponents:]: components cannot be nil
Future exception.
A few of these errors are going to be reported with this complaint, then further violations will simply be ignored.
答案 0 :(得分:2)
tl; dr 确保fromDate
参数不是。
解释:
当你给它一个零NSCalendar
时, NSDate
不知道如何处理这种情况。 API会向您发出警告,而不是抛出崩溃异常。请注意,由于API更改,此行为可能会发生变化并可能导致将来崩溃。