Re: Garbage collector vs variable lifetime
Re: Garbage collector vs variable lifetime
- Subject: Re: Garbage collector vs variable lifetime
- From: Charles Srstka <email@hidden>
- Date: Tue, 10 Jun 2008 10:19:58 -0500
On Jun 9, 2008, at 1:39 PM, Chris Hanson wrote:
It is perfectly legal to return an NSMutableArray from a
hypothetical +(NSArray *)array method.
However, all the sender of that +(NSArray *)array message can know
is that the result can be treated as an NSArray. It can't know
whether an NSArray or NSMutableArray is returned (unless it does
extra work, like using -isKindOfClass:, which also happens to be
fragile).
Even isKindOfClass: won't work in this case, because NSArray and
NSMutableArray both usually end up being the same class, NSCFArray.
This class seems to be a subclass of NSMutableArray, and using
isKindOfClass: on it will always return YES for NSMutableArray, even
if it's not actually mutable.
I don't really know of any way to actually test whether an NSArray is
mutable or not programatically (well, I suppose you could try mutating
it and see if you catch an exception or not, but that's obviously not
a very good solution).
Charles
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden