Re: Newbie: Proper objc style
Re: Newbie: Proper objc style
- Subject: Re: Newbie: Proper objc style
- From: mmalcolm crawford <email@hidden>
- Date: Sun, 9 May 2004 22:31:56 -0700
On May 9, 2004, at 8:09 PM, Jorge Martins wrote:
1 - Is it good style to have a class return autoreleased instances
of NSMutableArray? Should such a method be called -arrayOfWhatever?
Kind of like a convenience constructor but in another class?
Perhaps more likely to be named something akin to
"objects{For,With}..." and return an NSArray, e.g.
Wouldn't this imply that I was just returning an existing object, and
that if the user wanted to keep it around, he or she would just
retain/release it? No big deal either way.
Given my personal heritage (see the EOF documentation), no it wouldn't
necessarily imply returning (an) existing object(s). By
conventionally, however, objects should always be returned autoreleased
unless otherwise documented -- it is the responsibility of the method
caller to retain them if they want.
What I am doing though, is actually building an array and the objects
it points to from scratch and autoreleasing it.
If the user doesn't retain it, it will be expensive to build another
one. We are talking about possibly really large arrays.
I consider this difference significant because, performance wise, it's
expensive to build arrays full of objects and I want it to be obvious
that this method is actually creating the array and the objects that
it references.
That's why it thought of naming it like a convenience constructor,
except that it's not an NSArray method, it's one of my class's.
Convenience constructors still return autoreleased objects.
<
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/
Concepts/ObjectOwnership.html>
My difficulty in naming this method made me wonder if I should be
doing it at all.
I don't think there's an issue here -- everyone follows the same set of
rules.
Unless there's some detail about your project I'm missing...?
mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.