• 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: Know about Mutability
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Know about Mutability


  • Subject: Re: Know about Mutability
  • From: Paul Sargent <email@hidden>
  • Date: Fri, 14 Jan 2005 12:34:04 +0000

Peter Maurer wrote:

Perhaps I over-trimmed -- the context was "But how do I know whether myDict is mutable or not?". Testing for isKindOfClass:[NSMutableDictionary class] does not work as you might expect...


I'm confused about why respondsToSelector: isn't working correctly... Either the object will handle the selector (and respondsToSelector: returns true) or it doesn't and respondsTo returns false?
Or is this object somehow not strictly an Objective C object and therefore doesn't properly handle respondsToSelector but actually properly handles the setObject:forkey: message? Or... ?


You can rephrase Mmalcolm's statement as follows: Subclasses of NSMutableDictionary are not necessarily mutable. (NSCFDictionary is obviously a subclass of NSMutableDictionary -- AFAIK, cocoa's dictionary classes are all subclasses of NSMutableDictionary, even though that's not what the documentation says.)

Sounds to me like the design of these classes is backwards.

I was always taught that if you made a sub-class of a super-class, then the sub-class had to support all of the methods of the super-class. therefore preserving the 'is-a' paradigm (sp?). In this case a NSMutableDictionary 'is-a' NSDictionary, but the same cannot be said the other way round. Overriding methods to raise exceptions sounds like a hack because of this.

Is there a good reason that NSDictionary inherits from NSMutableDictionary, rather than the other way round?

Paul
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Know about Mutability
      • From: Shawn Erickson <email@hidden>
    • Re: Know about Mutability
      • From: James Bucanek <email@hidden>
    • Re: Know about Mutability
      • From: Angela Brett <email@hidden>
References: 
 >Re: Know about Mutability (From: James Bucanek <email@hidden>)
 >Re: Know about Mutability (From: mmalcolm crawford <email@hidden>)
 >Re: Know about Mutability (From: Andrew Pinski <email@hidden>)
 >Re: Know about Mutability (From: mmalcolm crawford <email@hidden>)
 >Re: Know about Mutability (From: Hugh Hoover <email@hidden>)
 >Re: Know about Mutability (From: Peter Maurer <email@hidden>)

  • Prev by Date: Re: Convert String into Expression
  • Next by Date: Re: Bindings Book !!!!!
  • Previous by thread: Re: Know about Mutability
  • Next by thread: Re: Know about Mutability
  • Index(es):
    • Date
    • Thread