• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Objective 2.0 properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective 2.0 properties


  • Subject: Re: Objective 2.0 properties
  • From: Jim Correia <email@hidden>
  • Date: Fri, 17 Oct 2008 13:38:43 -0400

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@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


  • Follow-Ups:
    • Re: Objective 2.0 properties
      • From: "Ignacio Enriquez" <email@hidden>
References: 
 >Objective 2.0 properties (From: "Ignacio Enriquez" <email@hidden>)
 >Re: Objective 2.0 properties (From: Charles Steinman <email@hidden>)
 >Re: Objective 2.0 properties (From: "Ignacio Enriquez" <email@hidden>)

  • Prev by Date: Re: Objective 2.0 properties
  • Next by Date: Re: Window widgets
  • Previous by thread: Re: Objective 2.0 properties
  • Next by thread: Re: Objective 2.0 properties
  • Index(es):
    • Date
    • Thread