On Feb 25, 2016, at 22:15 , Uli Kusterer <witness.of.teacht...@gmx.net> wrote:
> 
> Did you really mean +newBlah ? Not something like +blahWithX: or just +blah? 
> Because +new is documented to just be a shorthand for +alloc followed by 
> -init on the result, so +newBlah behaving differently than +new sounds kinda 
> inconsistent to me. Did I miss a serious gotcha there?

No, you’re correct. I was making a valid point using the wrong example.

As you said, if the name of a class method begins with “new”, it belongs to the 
“new” family, and it’s implicitly marked with 
'__attribute__((ns_returns_retained))’. That means it has +1 semantics.

What I was actually thinking of was factory methods that *don’t* begin with 
“new”, such as -[NSArray array]. These typically have +0 semantics. My point 
(which I think I’ve now demonstrated pretty vividly) is that if you don’t 
remember what the conventions are, it’s easy to go wrong in MMR.

Interestingly, in the old days, people argued about whether to do [[NSArray 
alloc] init] or [NSArray array], based on clarity vs. efficiency (avoidance of 
an autorelease). As soon as ARC took charge, no one cared any more, because ARC 
offered at least the possibility of both forms being efficient at run time. Now 
that we have conversions into Swift, using compatible naming of factory methods 
is important again. Plus ça change, …

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to