FROM : Scott Stevenson
DATE : Sun Jan 06 04:49:26 2008
On Jan 5, 2008, at 7:10 PM, André Pang wrote:
> 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.
Retaining a mutable object means you have no idea how its collection
will change outside of your control. It doesn't matter as much with
immutable objects, of course. NSMutableString is another good example
of needing a mutable copy, rather than just a retain.
Design-wise, you could decide to never have mutable objects as
instance variables and just re-set the entire array each time -- but
that seems a bit odd when you have thousands of items in a collection,
since each of the members would likely need to get a retain when you
duplicate it. It might also make it difficult to bind the array to an
NSArrayController.
- Scott_______________________________________________
MacOSX-dev mailing list
<email_removed>
http://www.omnigroup.com/mailman/listinfo/macosx-dev
DATE : Sun Jan 06 04:49:26 2008
On Jan 5, 2008, at 7:10 PM, André Pang wrote:
> 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.
Retaining a mutable object means you have no idea how its collection
will change outside of your control. It doesn't matter as much with
immutable objects, of course. NSMutableString is another good example
of needing a mutable copy, rather than just a retain.
Design-wise, you could decide to never have mutable objects as
instance variables and just re-set the entire array each time -- but
that seems a bit odd when you have thousands of items in a collection,
since each of the members would likely need to get a retain when you
duplicate it. It might also make it difficult to bind the array to an
NSArrayController.
- Scott_______________________________________________
MacOSX-dev mailing list
<email_removed>
http://www.omnigroup.com/mailman/listinfo/macosx-dev






Cocoa mail archive

