On 12/4/2006, at 23:37, Mark Grimes wrote:
[...] Clearly fThing is not defined so return fThing makes no sense in a getter accessor method. Nor does instantiating another string object in the setter method.
As for fThing, I have no idea. I guess f is a prefix to signal “instance variable.” I don’t see anything new instantiated in the setter though. It makes a copy of the ivar pointer, copies the new value to the ivar, and the releases the old ivar via the copied pointer.
I did however update it, now that you brought it up. I removed a few of your placeholders, here’s what I am left with:
- (NSString *)${1:thing} { return ${2:$1}; }
- (void)set${1/.*/\u$0/}:(NSString *)${3:a${1/.*/\u$0/}} { $3 = [$3 copy]; [$2 release]; $2 = $3; }
[This models the string accessor implementation defined in Hillegass ... if it's not correct, maybe someone should tell Aaron.]
I beleive Apple had a Cocoa Intro section up on ADC (from WWDC) long ago where they spent at least 15 minutes talking about several different strategies with respect to writing getters and, in particular, setters -- each with their own advantages.
For example should you retain/autorelease in your getter (what if A gets your value, then B sets a new value, now A is holding a pointer to a released object, but this may be in teh same “cycle”, so A is in good faith) -- should you autorelease your ivar in the setter (another solution to the previous problem), should you retain or copy, etc.