Re: Mutability
Re: Mutability
- Subject: Re: Mutability
- From: John Hörnkvist <email@hidden>
- Date: Tue, 20 Nov 2001 18:44:51 +0100
On Tuesday, November 20, 2001, at 03:24 , John C. Randolph wrote:
On Monday, November 19, 2001, at 10:07 AM, Norbert Heger wrote:
But be aware of the fact, that even if an instance is immutable, it
will be
a subclass of a mutable (abstract) superclass. Thus invoking [array
isKindOfClass:[NSMutableArray class]] will NOT tell you if the given
array
is in fact mutable. Instead it always returns YES.
That's exactly reversed from what the docs and the headers both say
about all of the Foundation collection classes. NSArray is the parent
of NSMutableArray, NSSet is the parent of NSMutableSet, and so forth.
From a type system point of view, the immutable classes differ only in
defining fewer methods than their mutable correspondents. For that
reason, the immutable classes cannot be subclasses of mutable classes.
However, 10.0 behaved like Norbert describes; all collections were
mutable. Apple chose not to implement a immutable collections, and used
mutable collections everywhere instead. This, coupled with Objective-C's
weak static type system, made some bugs very hard to detect.
Regards,
John Hornkvist
--
ToastedMarshmallow, the perfect Cocoa companion
http://www.toastedmarshmallow.com