Why "*later" point to a object too?


#1

[code]#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{

@autoreleasepool {
    
    NSDate *now = [NSDate date];
    NSLog(@"the new date lives at %@", now);
    double seconds = [now timeIntervalSince1970];
    NSLog(@"It has been %f seconds since the start of 1970", seconds);
    
    NSDate *later = [now dateByAddingTimeInterval:100000];
    NSLog(@"In 100,000 seconds, it will be %@", later);
    
}
return 0;

}[/code]

In the paragraph above the Figure 12.3 Object diagram for TimeAfterTime
the auther said :
The two variables now and later are part of the frame for the function main().They point to the NSDate objects, as shown by the arrows.

i know “now” is a pointer to a NSDate object, but why “later” is a pointer to an NSDate object, i think it is just a pointer to an NSDate object’s data, because in “NSDate *later = [now dateByAddingTimeInterval:100000];” the dateByAddingTimeInterval method was not sent to a NSDate class but a object point by now , and it return the address of the data of a NSDate not the NSDate itself…


#2

They are both NSDate objects because dateByAddingTimeInterval: method returns a new NSDate object.

You can easily convince yourself by doing this:

//  main.m

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
    @autoreleasepool {
        
        NSDate *now = [NSDate date];
        NSLog (@"the new date lives at %@", now);
        double seconds = [now timeIntervalSince1970];
        NSLog(@"It has been %f seconds since the start of 1970", seconds);
        
        NSDate *later = [now dateByAddingTimeInterval:100000];
        NSLog (@"In 100,000 seconds, it will be %@", later);
        
        NSLog (@"%s: ---> now:   %@", __PRETTY_FUNCTION__, [now className]);
        NSLog (@"%s: ---> later: %@", __PRETTY_FUNCTION__, [later className]);
        NSLog (@"%s: ---> now:   %d", __PRETTY_FUNCTION__, [now isKindOfClass:[NSDate class]]);
        NSLog (@"%s: ---> later: %d", __PRETTY_FUNCTION__, [later isKindOfClass:[NSDate class]]); 
        NSLog (@"%s: ---> now:   %d", __PRETTY_FUNCTION__, [now isMemberOfClass:[NSDate class]]);
        NSLog (@"%s: ---> later: %d", __PRETTY_FUNCTION__, [later isMemberOfClass:[NSDate class]]);                                                        
    }
    return 0;
}

Output:

2013-03-23 23:48:27.418 TimeAfterTime[68989:403] the new date lives at 2013-03-23 13:18:27 +0000
2013-03-23 23:48:27.419 TimeAfterTime[68989:403] It has been 1364044707.414832 seconds since the start of 1970
2013-03-23 23:48:27.419 TimeAfterTime[68989:403] In 100,000 seconds, it will be 2013-03-24 17:05:07 +0000
2013-03-23 23:48:27.420 TimeAfterTime[68989:403] int main(int, const char **): ---> now:   __NSDate
2013-03-23 23:48:27.420 TimeAfterTime[68989:403] int main(int, const char **): ---> later: __NSDate
2013-03-23 23:48:27.421 TimeAfterTime[68989:403] int main(int, const char **): ---> now:   1
2013-03-23 23:48:27.421 TimeAfterTime[68989:403] int main(int, const char **): ---> later: 1
2013-03-23 23:48:27.421 TimeAfterTime[68989:403] int main(int, const char **): ---> now:   0
2013-03-23 23:48:27.422 TimeAfterTime[68989:403] int main(int, const char **): ---> later: 0

#3

[quote=“ibex10”]They are both NSDate objects because dateByAddingTimeInterval: method returns a new NSDate object.

You can easily convince yourself by doing this:

//  main.m

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
    @autoreleasepool {
        
        NSDate *now = [NSDate date];
        NSLog (@"the new date lives at %@", now);
        double seconds = [now timeIntervalSince1970];
        NSLog(@"It has been %f seconds since the start of 1970", seconds);
        
        NSDate *later = [now dateByAddingTimeInterval:100000];
        NSLog (@"In 100,000 seconds, it will be %@", later);
        
        NSLog (@"%s: ---> now:   %@", __PRETTY_FUNCTION__, [now className]);
        NSLog (@"%s: ---> later: %@", __PRETTY_FUNCTION__, [later className]);
        NSLog (@"%s: ---> now:   %d", __PRETTY_FUNCTION__, [now isKindOfClass:[NSDate class]]);
        NSLog (@"%s: ---> later: %d", __PRETTY_FUNCTION__, [later isKindOfClass:[NSDate class]]); 
        NSLog (@"%s: ---> now:   %d", __PRETTY_FUNCTION__, [now isMemberOfClass:[NSDate class]]);
        NSLog (@"%s: ---> later: %d", __PRETTY_FUNCTION__, [later isMemberOfClass:[NSDate class]]);                                                        
    }
    return 0;
}

Output:

[code]
2013-03-23 23:48:27.418 TimeAfterTime[68989:403] the new date lives at 2013-03-23 13:18:27 +0000
2013-03-23 23:48:27.419 TimeAfterTime[68989:403] It has been 1364044707.414832 seconds since the start of 1970
2013-03-23 23:48:27.419 TimeAfterTime[68989:403] In 100,000 seconds, it will be 2013-03-24 17:05:07 +0000
2013-03-23 23:48:27.420 TimeAfterTime[68989:403] int main(int, const char **): —> now: __NSDate
2013-03-23 23:48:27.420 TimeAfterTime[68989:403] int main(int, const char **): —> later: __NSDate
2013-03-23 23:48:27.421 TimeAfterTime[68989:403] int main(int, const char **): —> now: 1
2013-03-23 23:48:27.421 TimeAfterTime[68989:403] int main(int, const char **): —> later: 1
2013-03-23 23:48:27.421 TimeAfterTime[68989:403] int main(int, const char **): —> now: 0
2013-03-23 23:48:27.422 TimeAfterTime[68989:403] int main(int, const char **): —> later: 0

[/code][/quote]

Thanks very much, you had make it clear to me.