Re: Know about Mutability
Re: Know about Mutability
- Subject: Re: Know about Mutability
- From: Peter Maurer <email@hidden>
- Date: Fri, 14 Jan 2005 08:12:20 +0100
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.)
The same goes for other non-/mutable class clusters: Testing if your
object -isKindOf: (i.e., is a member of a subclass of) a mutable class
is never a valid way to determine whether your object is actually
mutable.
I had to learn this the hard way, too ;-) And I ended up turning all
the objects in question into mutable ones. Thus, I never have to check
for mutability, which --as others have stated-- is simply impossible as
of now.
Peter.
PS: Here's one more vote for a public [myNSObject isMutable] method!
_______________________________________________
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