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