Re: subviews question
Re: subviews question
- Subject: Re: subviews question
- From: "Michael Ash" <email@hidden>
- Date: Thu, 31 Aug 2006 07:19:38 -0400
On 8/30/06, Mu Lin <email@hidden> wrote:
Hi, All:
I have a subclass of NSView say MyView only overide the drawRect
method, when I obtain subviews using following lines in my
appController:
MyView *aView; // outlet from nib
NSArray *mySubViews = [aView subViews];
Now the array mySubViews has some interesting properties, if a
subview is added or removed from aView, mySubViews updates
automatically, this is rather a surprise to me.
Seems to me - (NSArray *)subviews returns a reference of the
internal data representation or it is a singleton. The docs doesn't
mention anything about this. Any comments?
If the documentation doesn't say, then there are no guarantees. It
would be perfectly allowable for it to return a copy of its internal
array, or for it to simply return a reference to it. You must write
your code to deal with both cases. This isn't very hard; if you need
the array not to change, copy it, and if you need it to change, ask
the view for its subviews each time.
This isn't the only place you will see this. I know that NSTextView's
-string method does something similar, and it occurs in many other
places as well. Code according to what the docs promise, not according
to how you think things should act, and you'll be fine.
Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden