Changing a pointer after calling a function

Here are some simple points in my problem:

  • Using Xcode 6.0.1, if that matters, llvm 6.0 without optimization (DEBUG)
  • This happens in a separate thread launched with

    self.ioThread = [NSThread.alloc initWithTarget:self selector:@selector(initData) object:nil].autorelease;
    
  • Do not use ARC (does 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 designated "point of failure", she says:

-[__NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x7fdc2870

There are a couple of strange things about this setting that I cannot solve;

  • In the first line of the function, I already check the type of the object date.
  • In the debugger, when I say po dateand p date, these are the results that I get:

    (lldb) po date
    stamp
    
    (lldb) p date
    (NSDate *) $11 = 0x7fdc2870 @"stamp"
    
  • And when I go to the function that calls the function RFC3339DateString, and say p _updatedAtand 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 the pointers changed in the middle of the path. Does anyone understand the situation?

1; http://cl.ly/image/1n1l1E1i2a3y

2; http://cl.ly/image/2A0s3S2J0S1P

, RFC3339DateString; http://pastie.org/private/e7xzc3ntfz0p0d95g5hzw

+4
1

, _updatedAt . NSDate, NSString. , , .

, nil RFC3339DateString(), [NSMutableDictionary addObject:forKey:].

, , 'T' 'Z'.

+1

All Articles