执行以下代码后
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.
最佳答案
tl;dr 确保 fromDate
参数不是 nil。
解释:
NSCalendar
不知道如何处理当你给它一个 nil NSDate
的情况。 API 会向您发出警告,而不是抛出崩溃异常。请注意,此行为可能会发生变化,并可能在未来因 API 更改而导致崩溃。
关于ios - NSCFCalendar dateFromComponents : components cannot be nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31833363/