Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat kind of sarcastic error is this iOS?
    text
    copied!<p>I have some code I use to sort calendar dates that looks like this: </p> <pre><code>#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 </code></pre> <p>If I run it in the simulator all is ok. If I run it on the device I get this sarcastic debug message. </p> <blockquote> <p><strong>2012-09-19 22:40:13.972 APPNAME [4923:907] *</strong> -[__NSCFCalendar components:fromDate:]: date cannot be nil </p> <p>I mean really, what do you think that operation is supposed to mean with a nil date?</p> <p>An exception has been avoided for now.</p> <p>A few of these errors are going to be reported with this complaint, then further violations will simply silently do whatever random thing results from the nil. Here is the backtrace where this occurred this time (some frames may be missing due to compiler optimizations):</p> </blockquote> <p>You have to laugh at it but I'm not sure what is wrong with my <code>dateFormatFromTemplate:</code> code. Any help would be appreciated. </p> <p><em>Running Xcode V 4.5 btw</em> </p> <hr> <p>UPDATE:</p> <blockquote> <p>Backtrace:</p> <p>0 CoreFoundation 0x39ff0e55 + 84<br> 1 APPNAME 0x00040be1 -[MeetingsViewController dateAtBeginningOfDayForDate:] + 140</p> </blockquote> <p>So I guess things are going bad in my <code>dateAtBeginningOfDayForDate</code> method. Which looks like this:</p> <pre><code>/* 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; } </code></pre> <p>I use this method to break down a given NSDate to its' core components so that I can sort them all more efficiently. However, my app has to be international which is the reason behind using <code>NSLocale</code> to formate the date output. From what it seems I will need to alter my <code>dateAtBeginningOfDayForDate</code> to work internationally as well. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload