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

NSImmutableArray


  • Subject: NSImmutableArray
  • From: Andy Lee <email@hidden>
  • Date: Wed, 26 Jun 2002 16:11:23 -0400

Sorry to beat this horse again, but I just realized that you *can* have the compiler enforce the use of immutable Foundation objects (within your own code, at least) by declaring do-nothing subclasses. For example:

@interface MyImmutableArray : NSArray
{
}
@end

@implementation MyImmutableArray
@end

You can use MyImmutableArray variable almost anywhere you would have used NSArray. The difference is that your code can assume a MyImmutableArray will not mutate, if you ever have such a need. (I'm ignoring the case of a nasty typecast; if you typecast carelessly, you have to live with the consequences no matter how class libraries are designed.)

If Apple were to add a trivial "NSImmutableArray" subclass as above, it seems to me the whole problem would be reduced to a documentation bug. The class description for NSArray could say something like:

"An NSArray stores an array of objects, with array indices starting at zero. Instantiation messages sent to NSArray return immutable arrays by default. Subclasses may create mutable instances. See NSImmutableArray and NSMutableArray."

--Andy
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Mutable class problems (From: Marco Scheurer <email@hidden>)
 >Re: Mutable class problems (From: Andy Lee <email@hidden>)

  • Prev by Date: Re: Parsing XML
  • Next by Date: Re: NSPoint and NSRect
  • Previous by thread: Re: class docs (was: Re: Mutable class problems)
  • Next by thread: Archiving is Crashing first time...
  • Index(es):
    • Date
    • Thread