On 8 Dec 2008, at 17:15, [EMAIL PROTECTED] wrote:

There are a number of posts detailing with the ethics of the issue of determining an object's mutability.
eg: http://www.cocoabuilder.com/archive/message/cocoa/2004/7/7/111173
Does anyone have a current informed pragmatic opinion on how to deal with the following example?

I am not trying to determine program flow by determining mutability, merely trying to limit the number of self inflicted injuries. The following never seems to assert, regardless of whether dict is mutable or not.

NSAssert([dict isKindOfClass:[NSMutableDictionary class]], @"dict is not mutable");

I know that it is my responsibility to remain aware of an object's allocated class but sometimes I find myself wanting.

This is because NSDictionary is a class cluster. What happens behind the scenes is that Cocoa has a hierarchy of:

NSCFDictionary : NSMutableDictionary : NSDictionary

You are being handed an NSCFDictionary object which Cocoa has set up to be immutable internally. Try to use one of the mutable methods and it will throw an exception, but testing the class inheritance will suggest it is mutable.

Mike.

_______________________________________________

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