【发布时间】:2020-04-24 13:05:38
【问题描述】:
我正在从 DateComponentsFormatter 中获取崩溃报告。我无法复制自己,所以如果有人有解决方案或方法来复制它,我将非常感激。
0 CoreFoundation 0x1a0142a48 __exceptionPreprocess + 220 (NSException.m:199)
1 libobjc.A.dylib 0x19fe69fa4 objc_exception_throw + 56 (objc-exception.mm:565)
2 Foundation 0x1a0452e78 -[NSDateComponentsFormatter _canonicalizedDateComponents:withCalendar:usedUnits:withReferenceDate:] + 1436 (NSDateComponentsFormatter.m:101)
我调用它的代码如下所示:
let formatter = DateComponentsFormatter()
// `units` is a user customizable array of NSCalendar.Unit, limited to a subset of [.year, .month, .weekOfMonth, .day, .hour, .minute, .second]
formatter.allowedUnits = units
// `style` is a user choosable selection of the DateComponentsFormatter.UnitsStyle enum
formatter.unitsStyle = style
// `components` is a user customizable array of Calendar.Component, limited to a subset of [.year, .month, .weekOfMonth, .day, .hour, .minute, .second]
let dateComponents = Calendar.current.dateComponents(components, from: date1, to: date2)
print(formatter.string(from: dateComponents) ?? "")
我没有找到任何会引发此类异常的组合或日期。对这个函数的所有调用都发生在主线程上。
【问题讨论】:
标签: swift nsdateformatter ios13 nsdatecomponents dateformatter