• 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: properties attributes misunderstanding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: properties attributes misunderstanding


  • Subject: Re: properties attributes misunderstanding
  • From: Roland King <email@hidden>
  • Date: Wed, 30 Sep 2009 21:16:59 +0800

Other way around. The copy happens when you *set* the property.

	So ray.path = OriginalPathPointerYouStartedWith;

will copy OriginalPathPointerYouStartedWith and then set ray's member variable to that copy. However when you READ the property, it just returns what's in the member variable over and over again.

If you wanted it to return a copy you could if you wish write your own accessor

-(NSBezierPath*)path
{
	return( [ [ path copy ] autorelease ] );
}

which would copy it when it's accessed and give the accessor its own one to play with. So it would be copied when you set it, and then copied when you returned it. I'm not totally sure how much I like that, it feels a little semantically wrong to me but in the context of your class that might make sense. Were I really going to do that I may not use a property at all and might have a method which is called

	(NSBezierPath*)copyPath

which explicitly returns a copy of the path because that's clear.

On 30-Sep-2009, at 9:02 PM, Colin Howarth wrote:

Hi,

I have a class


@interface Ray : NSObject {

	...
	NSBezierPath		*path;
	...
}
@property (copy)	NSBezierPath	*path;
@end


an instance of which is accessed in another class:


- (void)drawRect:(NSRect)rect
{
NSBezierPath *temporaryPathPointerWhichIsSupposedToBeDifferent;
...
temporaryPathPointerWhichIsSupposedToBeDifferent = [ray.path];
[temporaryPathPointerWhichIsSupposedToBeDifferent transformUsingAffineTransform: aVeryLongDescriptiveTransformName];
[temporaryPathPointerWhichIsSupposedToBeDifferent stroke];
...
}



I thought the (copy) attribute would mean that temporaryPathPointerWhichIsSupposedToBeDifferent would be, well, a copy of the original path instance (which conforms to the NSCopying protocol). Of course, the compiler doesn't care what *I* think should happen, and applies the transform to path (which is identical to temporaryPathPointerWhichIsSupposedToBeDifferent).


It works if I do:

	temporaryPathPointerWhichIsSupposedToBeDifferent = [ray.path copy];

instead.

Why isn't it doing what I think it should do though?


Thanks,


colin _______________________________________________

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

_______________________________________________

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: properties attributes misunderstanding
      • From: Colin Howarth <email@hidden>
References: 
 >properties attributes misunderstanding (From: Colin Howarth <email@hidden>)

  • Prev by Date: Re: properties attributes misunderstanding
  • Next by Date: Re: properties attributes misunderstanding
  • Previous by thread: Re: properties attributes misunderstanding
  • Next by thread: Re: properties attributes misunderstanding
  • Index(es):
    • Date
    • Thread