Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Script Menu: Code generation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Script Menu: Code generation




On 28 dec 2005, at 23.17, Alexander von Below wrote:

the very useful Scripts menu of Xcode contains an item to create accessor definitions.

While it is most certainly correct, I am wondering why it produces:

- (id) x {
	return [[x retain] autorelease];
}

Is this not redundant? Why not just return x?

Some people seem to prefer that pattern:

<http://www.stepwise.com/Articles/Technical/2002-06-11.01.html/>

Personally, I find it to be wasteful and overly complex for no good reason.

I guess that the setter code is a matter of preference. The original code copies the new value, I have edited it to retain the value.

In a *generic* setter method, copy is probably the correct and safe operation. For immutable objects, copy is often replaced with retain as an optimization:


<http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/ Tasks/ImplementCopy.html#//apple_ref/doc/uid/20000049-999791>

j o a r



Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Script Menu: Code generation (From: Alexander von Below <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.