Re: ARC code in a non ARC app. iOS
Re: ARC code in a non ARC app. iOS
- Subject: Re: ARC code in a non ARC app. iOS
- From: Quincey Morris <email@hidden>
- Date: Thu, 25 Feb 2016 22:41:18 -0800
- Feedback-id: 167118m:167118agrif8a:167118sGVTIna0Eu:SMTPCORP
On Feb 25, 2016, at 22:15 , Uli Kusterer <email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden