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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to