I'm getting the weirdest error when I run this on my device (but not on simulator):
I am getting a date from a JSON object, like this:
NSDateFormatter *df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"EEE MMM d HH:mm:ss Z yyyy"];
NSDate *dateX = [df dateFromString: [info objectForKey:@"created_at"]];
NSUInteger desiredComponents = NSYearCalendarUnit | NSMonthCalendarUnit |
NSWeekCalendarUnit | NSHourCalendarUnit |
NSDayCalendarUnit | NSMinuteCalendarUnit |
NSSecondCalendarUnit;
NSDateComponents *elapsedTimeUnits = [[NSCalendar currentCalendar]
components:desiredComponents
fromDate:dateX
toDate:[NSDate date]
options:0];
As you can see, I use the formatter to convert the string into a date, which works. Then I create the NSDateComponents, and later use that to do elapsedTimeUnits.hour
and .day
etc. to calculate the amount of time from dateX
to NSDate date
(NOW).
And it works! Or so I thougt, while testing everything on the simulator.
I just got this insane errormessage saying dateX was nil, but only when I ran it on my device. So every time I run this in the simulator, it shows the correct amount of time from the date. When I run it on the device, it shows one specific date, which is 4 weeks, 1 day and 23 hours ago. I have NSLogged out the [info objectForKey:@"created_at"]
, and knows it gets the correct date as input to begin with. Apparently, the app can't do the converting from string to date on the device, but on the simulator. Everything from here on out is the output I get:
2012-08-31 00:26:19.773 App[1676:907] *** -[__NSCFCalendar
components:fromDate:toDate:options:]: fromDate cannot be nil
I mean really, what do you think that operation is supposed to mean with a nil fromDate?
An exception has been avoided for now.
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):
(
0 CoreFoundation 0x36a5e8bf <redacted> + 86
1 App 0x00082d67 -[NewsViewController tableView:cellForRowAtIndexPath:] + 478
2 UIKit 0x384d1b81 <redacted> + 412
3 UIKit 0x384b693b <redacted> + 1310
4 UIKit 0x384cde17 <redacted> + 206
5 UIKit 0x38489f2b <redacted> + 258
6 QuartzCore 0x357d7e9b <redacted> + 214
7 QuartzCore 0x357d7a39 <redacted> + 460
8 QuartzCore 0x357d8975 <redacted> + 16
9 QuartzCore 0x357d8353 <redacted> + 238
10 QuartzCore 0x357d8161 <redacted> + 316
11 UIKit 0x3849000b <redacted> + 126
12 CoreFoundation 0x36a8caed <redacted> + 20
13 CoreFoundation 0x36a8ade1 <redacted> + 276
14 CoreFoundation 0x36a8b137 <redacted> + 742
15 CoreFoundation 0x369fe39d CFRunLoopRunSpecific + 356
16 CoreFoundation 0x369fe229 CFRunLoopRunInMode + 104
17 GraphicsServices 0x353b331b GSEventRunModal + 74
18 UIKit 0x384da8f9 UIApplicationMain + 1120
19 App 0x0006107f main + 86
20 App 0x0005f450 start + 40
)