Re: Determining whether a dictionary is mutable or not
Re: Determining whether a dictionary is mutable or not
- Subject: Re: Determining whether a dictionary is mutable or not
- From: "email@hidden" <email@hidden>
- Date: Fri, 14 Jan 2011 12:15:47 +0000
On 14 Jan 2011, at 11:43, Clark Cox wrote:
> On Fri, Jan 14, 2011 at 3:34 AM, email@hidden
> <email@hidden> wrote:
>>
>>
>> On 14 Jan 2011, at 11:25, Tito Ciuro wrote:
>>
>>> 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
>>>
>>
>> In this case just check if your object responds to setObject:forKey:
>> If it does its mutable, if not it isn't.
>
> Unfortunately, that will not work. Internally, both NSDictionary and
> NSMutableDictionary are implemented by the same class; even
> NSDictionary responds to -setObject:forKey: (it won't do much other
> than throw an exception if called, but it implements it nonetheless)
>
You are quite correct. I had forgotten the detail of this. Apologies.
Apple's take on this is to choose a method signature and stick to it.
You can, however, dig the mutability info out if you really want to.
You can use -classForCoder and that will give you either NSDictionary
or NSMutableDictionary.
Regards
Jonathan Mitchell
Developer
Mugginsoft LLP
http://www.mugginsoft.com_______________________________________________
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