[NSDate date] vs [[NSDate alloc] init]


#1

I’m not sure that I see the difference between [NSDate date] and [[NSDate alloc] init]. I understand the alloc/init piece, but what I’m having trouble grasping is the difference between the two. Does “date” only initialize the date class method, while the “alloc/init” initializes all class methods within NSDate (which includes date, plus others)?

Looking it up in the documentation, it appears to be the same, hrmm, wait, it isn’t. Date is just a value, but init returns an object, is that it?

date: "Creates and returns a new date set to the current date and time."
init: “Returns an NSDate object initialized to the current date and time.”


#2

They are equivalent.

In the days before ARC, the memory management was different. (For future reference: date resulted in a autoreleased object, alloc/init resulted in an object that was not autoreleased)

In the ARC world, you can consider them completely equivalent.


#3

[quote=“AaronHillegass”]They are equivalent.

In the days before ARC, the memory management was different. (For future reference: date resulted in a autoreleased object, alloc/init resulted in an object that was not autoreleased)

In the ARC world, you can consider them completely equivalent.[/quote]

In the brave new ARC world would [NSDate new]; be equivalent as well?


#4

Yes. Even in the old work [NSDate new] was exactly equivalent to [[NSDate alloc] init].