Re: NSArray behavior changes?
Re: NSArray behavior changes?
- Subject: Re: NSArray behavior changes?
- From: "Erik M. Buck" <email@hidden>
- Date: Sat, 29 Sep 2001 08:53:33 -0500
>
> Instances of immutable classes generally should not make copies
>
> on -copy, but just return themselves retained...
>
>
If it doesn't do a copy, why is it called "copy"?
>
If you merely want to retain, why not do a retain?
>
Optimizing -copy to merely retain immutable objects takes advantage of
polymorphism.
object = [otherObject copy]; // does the right thing no matter what type
otherObject
If I want to retain immutable objects and copy mutable ones without the
defined behavior then I would have to write something like the following:
if([otherObject isMutable]) {
object = [otherObject copy];
} else {
object = [otherObject retain];
}
Not only is the above ugly, but there is no -isMutable method!
Merely retaining an immutable object is safe by definition since the
immutable object can't change.