• 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: Andy Lee <email@hidden>
  • Date: Fri, 14 Jan 2011 11:36:22 -0500

On Jan 14, 2011, at 7:57 AM, Roland King wrote:
> Again let me say that if the signature to your method is
>
> 	-(void)doSomethingWithADictionary:(NSDictionary*)dictionary;
>
> you shouldn't be trying to figure out whether that dictionary is mutable and mutate it.

Yup.

> If you want it to be otherwise make the signature
>
> 	-(void)doSomethingWithADictionaryICanReallyMessUpForYou:(NSMutableDictionary*)dictionary
>
> and make all the callers send mutable objects they know they don't need later and which they are forewarned you may be messing about with.

I suggest letting the caller tell you what kind of dictionary it is sending.  Have two different methods:

    -(void)doSomethingWithADictionary:(NSDictionary*)dictionary;
    -(void)doSomethingWithAMutableDictionary:(NSMutableDictionary*)dictionary;

Have each of these call a private method that does the real work:

    -(void)_privatelyDoSomethingWithAPossiblyMutableDictionary:(id)dictionary
                                                       mutable:(BOOL)isMutable;

Instead of trying to test the dictionary object for mutability (which won't work), simply check isMutable.

--Andy

_______________________________________________

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: Tito Ciuro <email@hidden>)
 >Re: Determining whether a dictionary is mutable or not (From: Roland King <email@hidden>)

  • Prev by Date: Re: UIEvent timestamp clarification
  • Next by Date: Re: NSUndoManager retain/release of arguments - ad infinitum
  • 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