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

Re: Mutability


  • Subject: Re: Mutability
  • From: Vince DeMarco <email@hidden>
  • Date: Tue, 20 Nov 2001 15:43:57 -0800

On Tuesday, November 20, 2001, at 01:03 pm, Peter Ammon wrote:

On Monday, November 19, 2001, at 01:07 PM, Norbert Heger wrote:

Fortunately we now have real immutable collection classes (in 10.0 all
collection classes were mutable). Copying an immutable instance now simply
retains and returns the very same object, and invoking a mutating method
raises an exception.

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.


[...]

Thanks for the heads up, I'm sure this would have bitten me sooner or later. So what's the proper way to determine if a collection is mutable or not, if we can't use isKindOfClass: ?

Why do you care??

If you need a mutable version of a collection make a mutableCopy of it.

newDict= [myDictionary mutableDictionar];

[newDict setObject:@"foo" forKey:@"bar"];

do stuff with new Dict

[newDict release];

There is no way you can tell if a collection is mutable or not. But i would argue that you really don't need to know that.

vince


  • Follow-Ups:
    • Re: Mutability
      • From: Ondra Cada <email@hidden>
    • Re: Mutability
      • From: Angela Brett <email@hidden>
References: 
 >Re: Mutability (From: Peter Ammon <email@hidden>)

  • Prev by Date: Reference leak!!!
  • Next by Date: Re: Mixing Cocoa/Java problem
  • Previous by thread: Re: Mutability
  • Next by thread: Re: Mutability
  • Index(es):
    • Date
    • Thread