On May 10, 2012, at 11:54 PM, Ken Thomases wrote:

> On May 10, 2012, at 1:07 AM, Roland King wrote:
> 
>> My confusion comes from not knowing whether this function now returns an 
>> object with a +1 refcount or not. If it does it needs to be renamed to have 
>> new or copy etc in the method name, or annotated properly to show that.
> 
> I think you have this backward.  You are giving ownership over to ARC.  ARC 
> decides what to do in part based on the method name.  You don't pick the 
> method name to match the behavior you anticipate from ARC, ARC picks its 
> behavior based on the name, which should reflect your chosen semantics.
> 
> Since your method name doesn't indicate that it returns ownership, ARC will 
> autorelease the value.  [If the caller is also compiled with ARC, then it 
> hardly matters.  It will decide how to behave also based on the method name 
> and the two behaviors will complement each other (and, depending on 
> optimizations, cancel out so that neither an autorelease nor a retain 
> happens).  If the caller is MRC, then ARC autoreleasing the return value is, 
> of course, important given your method name.]
> 
> Regards,
> Ken
> 

Nicely put Ken and thanks too to Quincey who said much the same thing. I'd 
gotten stuck thinking that I had to figure out ownership and be explicit about 
it to match the method instead of understanding I just need to tell ARC what 
semantics I want when an object moves from CoreFoundation to Cocoa and let it 
sort it out what to do later based on the name and attributes of the method, 
which of course other code, ARC and non-ARC will then interpret correctly. 

ARC continues to be a very well thought out framework which hasn't let me down 
yet. 

Now back to the keychain API on iOS .. possibly not quite as coherent. 

Thanks both, I'm much happier now. 
_______________________________________________

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