Re: array = [NSArray new] or array = [NSArray array]?
Re: array = [NSArray new] or array = [NSArray array]?
- Subject: Re: array = [NSArray new] or array = [NSArray array]?
- From: Quincey Morris <email@hidden>
- Date: Fri, 19 Aug 2016 13:46:24 -0700
- Feedback-id: 167118m:167118agrif8a:167118sPviqTo1R6:SMTPCORP
On Aug 19, 2016, at 12:33 , email@hidden wrote:
>
>> AFAICT, the main reason *not* to use ‘new’ is to avoid generating anxiety for those who come back to read the code later, and who might worry that the inconsistency means something.
>
> Even though new has been a synonym for alloc] init] for decades.
I really just meant anxiety about one app using two different patterns for the same thing. Same thing if the app used “new” in some places and “alloc/init” in others.
On Aug 19, 2016, at 10:53 , Charles Srstka <email@hidden> wrote:
>
> [NSArray array] is a synonym for [[[NSArray alloc] init] autorelease].
(along with other similar comments in other responses)
To be pedantic, it’s *implemented* as [[[NSArray alloc] init] autorelease], but the lack of an API contract to that effect means that “synonym” isn’t quite accurate.
My point is that Apple might revisit the implementation of NSArray at any time (in these Swiftian days, stranger things have happened), and choose to write it with full ARC compatibility, which means there might not be any autorelease when invoked from ARC client code, since ARC can optimize the code when it handles both ends of the invocation.
_______________________________________________
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