Where do you get the "message"?


#1

I’m having difficulty understanding where the “message” comes from.

        NSDate *now = [NSDate date];
        NSLog(@"The new date is %@", now);
        
        double seconds = [now timeIntervalSince1970];
        NSLog(@"It has been %f seconds since the start of 1970.", seconds);

In the first part, if NSDate is the object and date is the message, then where was date defined/initialized?

In the second part, if timeIntervalSince1970 is the message, why can’t I use timeIntervalSince1980 as the message?

Any help would be appreciated, thanks.


#2

NSDate is the class.
now is a pointer to an instance of NSDate.
date is the name of a class method.
timeInterval is the name of an instance method.
There are two message sends:

and


#3

Thanks for the quick response Aaron. I’ve been doing some extra reading and it’s starting to slowly make sense.

What seemed strange was the reference to 1970. Why 1970 and not, say 2000? Then I did a “Jump to Definition” to see that it was specifically defined as an instance for NSDate. So that’s where it came from. We could have also used: earlierDate, laterDate, timeIntervalSinceDate…


#4

[quote=“razmanugget”]Thanks for the quick response Aaron. I’ve been doing some extra reading and it’s starting to slowly make sense.

What seemed strange was the reference to 1970. Why 1970 and not, say 2000? Then I did a “Jump to Definition” to see that it was specifically defined as an instance for NSDate. So that’s where it came from. We could have also used: earlierDate, laterDate, timeIntervalSinceDate…[/quote]

January 1, 1970 12:00 AM is the UNIX Epoch. For all UNIXy systems like OS X, iOS, Linux, Solaris, etc it’s where time begins.

Since FreeBSD begat NextStep which begat OS X which begat iOS; Apple uses the epoch.


#5

Thanks macshome. That’s the exact clarification I was looking for.


#6

I also had the same question. The book never states that

timeIntervalSince1970] is an existing method of NSDate


#7

I’m also a little unsure about the terminology.

Firstly, are these two sentences identical in meaning?

dateOfBirth is a pointer to an instance of class NSDate
dateOfBirth is a pointer to an object of class NSDate

Secondly, if dateOfBirth is just the pointer, then what do you call the object / instance itself? Or, for practical purposes do you just refer to the object / instance dateOfBirth?

[Or have I just misunderstood everything, again…?]

Many thanks - I’m really enjoying the book!

David


#8

Those sentences are identical in meaning.

We don’t refer to the object with a name – only the pointer has a name.


#9

[quote=“AaronHillegass”]Those sentences are identical in meaning.

We don’t refer to the object with a name – only the pointer has a name.[/quote]

Thanks for the very quick reply!

I’m not sure I understand why the object itself (rather than the pointer) doesn’t have a name (even if it’s just ‘shorthand’) – but if it’s really not needed, or if the explanation is too complex at this stage, I’m content to worry about the other stuff I should be understanding instead…

Thanks again

David