• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Determining whether a dictionary is mutable or not
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Determining whether a dictionary is mutable or not


  • Subject: Re: Determining whether a dictionary is mutable or not
  • From: Roland King <email@hidden>
  • Date: Fri, 14 Jan 2011 19:43:04 +0800

On 14-Jan-2011, at 7:36 PM, Roland King wrote:

>
> On 14-Jan-2011, at 7:25 PM, 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
>>
>
> remember - write it first, optimize it later. If your app is slow and you run the performance tools on it and making mutable copies is what's causing you performance issues then by all means optimize it at that point. My suspicion would be that making mutable copies of existing dictionaries is a pretty fast operation, apple's pretty good at that stuff.
>
> One other idea, if your method wants a dictionary it can mutate, how about making that the signature and making it up to the caller to send something mutable, as it seems not entirely unlikely the caller knows what it has.
>

Hit send too fast ..

Also, if your caller can pass NSDictionary or NSMutableDictionary to your method that seems to indicate the method signature is .. NSDictionary. If I as a caller send something to a method which takes an NSDictionary, I would expect you not to mutate it, even if I happen to have sent you a mutable one. So either change the signature to be NSMutableDictionary, and if callers don't want you mutating the argument they can copy it before they send it you, or make a mutable copy of the argument for yourself every time and respect the method calling signature.

_______________________________________________

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

References: 
 >Determining whether a dictionary is mutable or not (From: Tito Ciuro <email@hidden>)
 >Re: Determining whether a dictionary is mutable or not (From: Mike Abdullah <email@hidden>)
 >Re: Determining whether a dictionary is mutable or not (From: Tito Ciuro <email@hidden>)
 >Re: Determining whether a dictionary is mutable or not (From: Roland King <email@hidden>)

  • Prev by Date: Re: Determining whether a dictionary is mutable or not
  • Next by Date: Re: Determining whether a dictionary is mutable or not
  • Previous by thread: Re: Determining whether a dictionary is mutable or not
  • Next by thread: Re: Determining whether a dictionary is mutable or not
  • Index(es):
    • Date
    • Thread