I have some code I use to sort calendar dates that looks like this:
#if !(TARGET_IPHONE_SIMULATOR)
NSString *formatString = [NSDateFormatter dateFormatFromT
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.
The error does not happen in the code you posted. It means somewhere you have something that is supposed to be an NSDate
and instead it's 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