• 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: NSArray behavior changes?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >NSArray behavior changes ? (From: Raphael Sebbe <email@hidden>)
 >Re: NSArray behavior changes? (From: jgo <email@hidden>)

  • Prev by Date: Re: "static" typing (Learning Cocoa Chapter 13)
  • Next by Date: OT: IrDA in 5G64
  • Previous by thread: Re: NSArray behavior changes?
  • Next by thread: Button() call not in 10.1
  • Index(es):
    • Date
    • Thread