Programing

이 iOS는 어떤 종류의 비꼬는 오류입니까?

lottogame 2020. 9. 22. 20:55
반응형

이 iOS는 어떤 종류의 비꼬는 오류입니까?


다음과 같은 달력 날짜를 정렬하는 데 사용하는 코드가 있습니다.

#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 APPNAME [4923 : 907] * -[__ NSCFCalendar components : fromDate :] : 날짜는 nil 일 수 없습니다.

제 말은, 그 작전이 무 날짜를 의미한다고 생각하십니까?

지금은 예외가 발생하지 않았습니다.

이러한 오류 중 몇 가지가이 불만 사항과 함께보고되고 추가 위반은 단순히 nil로 인한 임의의 결과를 조용히 수행합니다. 이번에 발생한 역 추적은 다음과 같습니다 (컴파일러 최적화로 인해 일부 프레임이 누락 될 수 있음).

당신은 그것을 비 웃어야하지만 내 dateFormatFromTemplate:코드에 무엇이 잘못되었는지 잘 모르겠습니다 . 어떤 도움을 주시면 감사하겠습니다.

Xcode V 4.5 btw 실행


최신 정보:

역 추적 :

0 CoreFoundation 0x39ff0e55 + 84
1 APPNAME 0x00040be1-[MeetingsViewController dateAtBeginningOfDayForDate :] + 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.

As for the humor in the error message, I have never seen that message, but +1 to Apple. Some engineer in the Cocoa division is as funny as the good old engineers Apple used to have a lot of time ago.

Check out the kind of diagnostics Apple's MPW C compiler used to spit out http://www.netfunny.com/rhf/jokes/91q3/cerrors.html


Much thanks to nneonneo for helping me figure this out.

My issue is that my app has to work internationally so I needed dates to display with respect to the user location. I thought that I would just create a NSDateFormatter to the users locale then pass in a string date like so:

 NSString *formatString = [NSDateFormatter dateFormatFromTemplate:@"HH:mm dd MMM yyyy" options:0
                                                              locale:[NSLocale currentLocale]];
date = [fmt dateFromString:[NSString stringWithFormat:@"%@ %@", obj.meetingTime, obj.meetingDate]];

However, the problem is that I was localization the date format before I passed in the string date. In my case NSDateFormatter looked like this after localizing.

MMM dd, yyyy, HH:mm

Which I the format after localization could look many different ways after localizing.

So passing in a string with a format of HH:mm dd MMM yyyy was causing it to return nil.

Which is obvious now -.-

So instead of localizing when I create the date, I create a the dates with a standard format of HH:mm dd MMM yyyy. Then when displaying, I format the NSDate to the users respective locale.

참고URL : https://stackoverflow.com/questions/12505833/what-kind-of-sarcastic-error-is-this-ios

반응형