tags:

views:

250

answers:

2

I'm quite familiar with the reasons for wanting to copy a property vs. retain. (Essentially the value vs. relationship argument. You almost always want to copy strings, for example.)

What about NSColor and NSGradient?

They both conform to NSCopying, but as currently implemented, are immutable.

Thoughts?

+2  A: 

Subclasses of NSColor and NSGradient that are assigned to your properties may not be immutable or referentially transparent, so you should still use the same logic for determining retain vs copy that you would for any object that has commonly used mutable subclasses, even though in practice it is unlikely to matter most of the time.

Louis Gerbarg
+3  A: 

Immutable objects will often implement their copyWithZone: method as return [self retain], since there's no point in making a separate copy of the data if it's never going to change. They still need to implement the method, though, to be compatible with anything that expects NSCopying conformance (e.g. NSDictionary keys).

As for usage, I would stick with the same usage patterns as other "value" properties, and you won't see any performance difference since they'll likely be calling retain from copy anyway. That also covers you for cases like the addition of a mutable subclass that has a non-trivial implementation of NSCopying.

Brian Webster