• 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: Hugh Hoover <email@hidden>
  • Date: Fri, 14 Jan 2005 07:54:52 -0800


On Jan 14, 2005, at 01:40, Peter Maurer wrote:

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?

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.)

bbbuuuut....
If the subclass instance >IS< mutable - then it responds to setObject:forKey:, right? (that is, if it DOESN'T - then it's not mutable!)
if it responds to setObject:forKey:, then it respondsToSelector: should return true, eh?

Is there a special reason why you haven't sent this message to the list?

oops - no... just hit reply instead of reply-all :)

My reply would be the following...

------

Given the fact that non-mutable dictionary classes are subclasses of NSMutableDictionary, they, too, respond to -setObject:forKey:. However, you are not allowed to use -setObject:forKey: for these non-mutable classes.

Thus, -respondsToSelector: @selector(setObject:forKey:) is not a valid way to determine mutability, as it always returns YES.

doh! of course - and although they respond, they refuse to actually DO anything with it - except perhaps to rudely except...




Please note that I might well be wrong, but that's what I've gathered from various discussions, including mail exchanges with those who should know.


------

... but I'd rather keep this on-list. Cheers,

Peter.


Hugh Hoover
_______________________________________________
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


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: Fastest way to build an attributed string
  • Next by Date: Re: Know about Mutability
  • Previous by thread: Re: Know about Mutability
  • Next by thread: Re: Know about Mutability
  • Index(es):
    • Date
    • Thread