Leopard Properties and NSMutable Array

Bill Bumgarner bbum at mac.com
Sat Jan 5 19:43:58 PST 2008


On Jan 5, 2008, at 7:10 PM, André Pang wrote:
> On 06/01/2008, at 12:53 PM, Bill Bumgarner wrote:
>> Which, unfortunately, is the alternative.   There is an enhancement  
>> request already to offer a mutablecopy keyword.
> Is there actually a use for a 'mutablecopy' keyword?  I ran into the  
> same problem as Jonathan, but then realised that retain semantics  
> are typically what you want for a mutable object.  I can't quite  
> think of a case where a mutable copy of the array in the class would  
> actually be useful.
>
> (Maybe that thought can be used as a possible warning: if you define  
> a property for a type that obeys the NSMutableCopying protocol,  
> perhaps a warning can be emitted if you use copy rather than  
> retain...)

There are uses for mutablecopy in that there has been more than one  
person that has filed a request for it. :)

Seriously, though, there are cases where mutablecopy makes a lot of  
sense.  Specifically, if your object model is such that your object  
wants to take ownership of the contents of the array and changes  
therein.   It is much easier to guarantee that a mutable array's  
contents haven't changed if you have isolated ownership of said  
mutable array;  copying on set and returning a copy on get.

Of course, that has efficiency / performance / memory implications  
and, thus, balance must be maintained between performance and bullet  
proof.

b.bum



More information about the MacOSX-dev mailing list