Another question about [[... alloc] init]


#1

Sorry guys for bringing this topic on… again…

On page 81 (under subtitle Nesting message sends) it’s stated that the [[… alloc] init];-manner is the only Apple-approved way to go.
But on the challenge of chapter 13 (NSTimeZone) NSDate *now = [NSDate date]; is used and/or in chapter 14 (NSHost - localizedName) b]NSHost *myHost = [[NSHost currentHost] localizedName];[/b] is used.
So, those two challenges don’t even use the [[… alloc] init]-way of defining…

My question is now: aren’t those two challenges not the Apple-approved way or am I missing something?

It’s all-in-all not clear to me when to use [[… alloc] init]; and when to use the other declaration/definition?


#2

They are all good as long as you take good care of ownership.
Apple calls them convenience-method invocations.
For example, [NSDate date] is a convenience-method invocation; it is doing the [[NSDate alloc] init…] on your behalf. So are the others.


#3

[quote=“ibex10”]They are all good as long as you take good care of ownership.
Apple calls them convenience-method invocations.
For example, [NSDate date] is a convenience-method invocation; it is doing the [[NSDate alloc] init…] on your behalf. So are the others.[/quote]
Now that’s what I call “clear info”.
Thank you very much!