Hi Mike,

Given that the caller can pass a NSDictionary or an NSMutableDictionary, I 
wanted to test its mutability before calling setObject:forKey:. In order to 
avoid calling mutableCopy each time, I thought it would be more efficient to 
test it and then call mutableCopy only when needed.

Thanks for the help,

-- Tito

On Jan 14, 2011, at 12:15 PM, Mike Abdullah wrote:

> If you want to test if a dictionary is immutable, you are almost certainly 
> doing it wrong. When passed a dictionary in to a method either:
> 
> A) Make a mutable copy if that's what you need
> B) -copy it if you want it to be immutable. (This is not inefficient as it 
> sounds because immutable objects implement -copy to do a -retain and return 
> self instead)
> 
> On 14 Jan 2011, at 10:48, Tito Ciuro wrote:
> 
>> Hello,
>> 
>> Trying to determine whether an NSDictionary is mutable or not fails with 
>> these two tests:
>> 
>> // Variable info could be NSDictionary or NSMutableDictionary. Assume it's 
>> an NSDictionary.
>> 
>> BOOL isKindOfClass = [info isKindOfClass:[NSMutableDictionary class]];
>> BOOL respondsToSelector = [info 
>> respondsToSelector:@selector(setObject:forKey:)];
>> 
>> After executing the above statements, both variables 'isKindOfClass' 
>> and'respondsToSelector' are set to YES.
>> 
>> When I obtain the class type of 'info', I get:
>> 
>> (gdb) po [info class]
>> NSCFDictionary
>> 
>> The question is: if 'info' is an immutable dictionary, why is isKindOfClass 
>> and respondsToSelector telling me that it is mutable?
>> 
>> Thanks,
>> 
>> -- Tito
>> _______________________________________________
>> 
>> 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/cocoadev%40mikeabdullah.net
>> 
>> This email sent to cocoa...@mikeabdullah.net
> 

_______________________________________________

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 arch...@mail-archive.com

Reply via email to