On Oct 17, 2008, at 1:25 PM, Ignacio Enriquez wrote:

Second: Let me see If I understood. they should be copy since all the
classes all conform to NSCopying. this means that all (and I mean ALL
) properties should be "copy"?? (since all objects inherits from
NSObject and this class conform to NSCopying!?) I Think I missing
something here.

What gives you the impression that NSObject (and thus all of its subclasses) conform to NSCopying?

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.

Consider a Person object.

Person *person1 = [[Person alloc] init];
Person *person2 = [[Person alloc] init];

NSMutableString *string = [NSMutableString string];

[string setString: @"Jim"];
person1.name = string;

[string setString: @"Ignacio"];
person2.name = string;

If name were specified as

        @property(retain) NSString *name;

then both people would now be named "Ignacio" (person1 having been changed by side effect), which is not what we want in this situation.

However, if we had a parent property, we are interested in the relationship to the parent (i.e. we don't want a separate copy), so retain, not copy, would be more appropriate here.

Jim
_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to