Reputation: 794
Here is some simple points about my problem;
This is happening on a separate thread launched with;
self.ioThread = [NSThread.alloc initWithTarget:self selector:@selector(initData) object:nil].autorelease;
Not using ARC (should not matter)
First code;
if (_updatedAt) // A simple C function call
data[@"updatedAt"] = RFC3339DateString(_updatedAt);
RFC3339DateString
function;
NSString* RFC3339DateString(NSDate* date) {
if (!date || ![date isKindOfClass:NSDate.class]) return nil;
NSDateFormatter *rfc3339DateFormatter = NSDateFormatter.new.autorelease;
NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"].autorelease;
[rfc3339DateFormatter setLocale:enUSPOSIXLocale];
[rfc3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];
[rfc3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
return [rfc3339DateFormatter stringFromDate:date]; // point of crash.
}
So, on the line I marked "point of crash", It says;
-[__NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x7fdc2870
There are couple strange things in this situration I cannot solve;
date
object.On debugger, when I say po date
and p date
, these are the results are I get;
(lldb) po date
stamp
(lldb) p date
(NSDate *) $11 = 0x7fdc2870 @"stamp"
And when I go to the function calling RFC3339DateString
function and say p _updatedAt
and po updatedAt
;
(lldb) p _updatedAt
(NSDate *) $12 = 0x7fd88a10 class name = __NSDate
(lldb) po _updatedAt
2014-09-27 06:37:33 +0000
I cannot understand how did the pointers changed in the middle of the way. Does anybody understand the situation?
Screenshot 1; http://cl.ly/image/1n1l1E1i2a3y
Screenshot 2; http://cl.ly/image/2A0s3S2J0S1P
Assembly Code around the code I'm calling RFC3339DateString function; http://pastie.org/private/e7xzc3ntfz0p0d95g5hzw
Upvotes: 4
Views: 94
Reputation: 9721
I would suspect _updatedAt
is being overwritten. Sometimes it contains an NSDate
and sometimes an NSString
. Add a watchpoint to see where it's being written to.
Also, you should never return nil
from RFC3339DateString()
as that will cause an exception within [NSMutableDictionary addObject:forKey:]
.
Lastly you don't need so many quotes in that date formatting string, just around 'T'
and 'Z'
.
Upvotes: 1