这是 iOS 的一个什么样的讽刺错误?

2024-01-31

我有一些用于对日历日期进行排序的代码,如下所示:

#if !(TARGET_IPHONE_SIMULATOR)
    NSString *formatString = [NSDateFormatter dateFormatFromTemplate:@"HH:mm dd MMM yyyy" options:0
                                                              locale:[NSLocale currentLocale]];
    [fmt setDateFormat:formatString];
#else
    [fmt setDateFormat:@"HH:mm dd MMM yyyy"];
#endif

如果我在模拟器中运行它一切正常。如果我在设备上运行它,我会收到这条讽刺性的调试消息。

2012-09-19 22:40:13.972 应用程序名称 [4923:907] *-[__NSCF日历 组件:fromDate:]:日期不能为零

我的意思是真的,你做什么 认为该操作应该意味着零日期?

目前已避免出现异常。

其中一些错误将会是 随此投诉一起举报,然后进一步的违规行为将只是 默默地做任何由 nil 产生的随机事情。这里是 回溯这次发生的情况(某些帧可能丢失 由于编译器优化):

你必须嘲笑它​​,但我不确定我的问题出在哪里dateFormatFromTemplate:代码。任何帮助,将不胜感激。

顺便说一句,运行 Xcode V 4.5


UPDATE:

回溯:

0 核心基础 0x39ff0e55 + 84
1 应用程序名称 0x00040be1 -[MeetingsViewController 日期AtBeginningOfDayForDate:] + 140

所以我想我的事情会变得很糟糕dateAtBeginningOfDayForDate方法。看起来像这样:

/*
 Break down a given NSDate to its bare components for sorting
 */
- (NSDate *)dateAtBeginningOfDayForDate:(NSDate *)inputDate
{
    // Use the user's current calendar and time zone
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
    [calendar setTimeZone:timeZone];

    // Selectively convert the date components (year, month, day) of the input date
    NSDateComponents *dateComps = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:inputDate];

    // Set the time components manually
    [dateComps setHour:0];
    [dateComps setMinute:0];
    [dateComps setSecond:0];

    // Convert back
    NSDate *beginningOfDay = [calendar dateFromComponents:dateComps];
    return beginningOfDay;
}

我使用这种方法将给定的 NSDate 分解为其核心组件,以便我可以更有效地对它们进行排序。但是,我的应用程序必须是国际化的,这就是使用的原因NSLocale格式化日期输出。从看来我需要改变我的dateAtBeginningOfDayForDate也可以在国际上工作。


您发布的代码中不会发生该错误。这意味着在某个地方你有一些应该是的东西NSDate相反,它是nil.

至于错误消息中的幽默,我从未见过该消息,但给苹果+1。 Cocoa 部门的一些工程师就像苹果公司很久以前的优秀老工程师一样有趣。

查看 Apple 的 MPW C 编译器用于吐出的诊断类型http://www.netfunny.com/rhf/jokes/91q3/cerrors.html http://www.netfunny.com/rhf/jokes/91q3/cerrors.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

这是 iOS 的一个什么样的讽刺错误? 的相关文章

随机推荐