Is NSDate *later a new instantiation?


#1

Hey Mikey,

GREAT BOOK, I’m working my way through it now. Thank you for Chapter 14, it really cleared up a LOT.

On page 96 there is a line:
NSDate *later = [now dateByAddingTimeInterval:100000];

I get that *now is instantiated by the class method “date” however, what exactly is going on with *later?

I understand that it is a pointer of type NSDate, but is it a pointer to a new NSDate object in memory? (I guess I could print out the address values, but I’m not sure that would really answer the question).

Is *later available to accept messages just like *now is?

Thanks in advance.


#2

Also, It looks like the same thing happens on page 110:

You have:
NSString *angryText = @“Thank makes me so mad!”;

Which makes sense that *angryText is instantiated as a string literal. But, then right under that line you have:

NSString *reallyAngryText = [angryText uppercaseString];

You also note that uppercaseString is an instance method vice class method, so to me, it shouldn’t instantiate *reallyAngryText

Maybe a better question is:
Is *reallyAngryText a copy of *angryText or is it a completely new object?

Thanks!


#3

In both cases you have created new instances, and in both cases they use memory.

later is a new instance of the NSDate class, its value is ‘now +100000’. now remains as it was originally. You can do to later what you could do to now as it inherits the methods available for now.

As for reallyAngryText, it is a new NSString instance that has “THANK MAKES ME SO MAD!” as its value. angryText remains as “Thank makes me so mad!”.

Ian


#4

Good deal, thanks for clearing that up.