Re: Objective 2.0 properties
Re: Objective 2.0 properties
- Subject: Re: Objective 2.0 properties
- From: Jim Correia <email@hidden>
- Date: Fri, 17 Oct 2008 14:29:52 -0400
On Oct 17, 2008, at 1:59 PM, Ignacio Enriquez wrote:
I think I am beginning to understand this.
What gives you the impression that NSObject (and thus all of its
subclasses)
conform to NSCopying?
I think I was wrong... I will read the documentation about this.
A property should be copy when you are interested in the *value* of
the
thing being set.
A property should be retain when you are interested in maintaining a
relationship to the thing being set.
How about assign ?
Please refer to the documentation for properties [1] and the object
ownership policy [2].
For object types, in a non-garbage collected application (traditional
retain/release style memory management) you never want to use assign.
It is the equivalent of hand writing an accessor that does a pointer
assignment (with no additional memory management) - i.e. it is
incorrect.
In a garbage collected application, assign and retain are equivalent.
But if the object does conform to NSCopying, it is better (and avoids
a compiler warning) to be explicit about whether you meant assign or
copy. This provides built-in documentation about your intent.
[1] http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_5_section_3.html#/
/apple_ref/doc/uid/TP30001163-CH17-SW2
[2] http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html
- Jim
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden