Re: Subclassing an object's creation method (NSBezierPath's +bezierPath)
Re: Subclassing an object's creation method (NSBezierPath's +bezierPath)
- Subject: Re: Subclassing an object's creation method (NSBezierPath's +bezierPath)
- From: Steve Sims <email@hidden>
- Date: Mon, 31 May 2004 17:13:46 -0400
Peter and Prachi,
Thanks for your feedback and suggestions
On 28 May 2004, at 04:47, Peter Maurer wrote:
+ (MyBez *)bezierPath
{
if (self = [super bezierPath])
{
[self setXLoc: 0];
[self setYLoc: 0];
}
return self;
}
Background information: You shouldn't use "self" here, because in
class methods such as yours, "self" refers to the class, not an
instance. Prachi's suggestion...
Ah - hence why I was getting the compilation errors I was seeing.
+ (MyBez *)bezierPath
{
MyBez *path = [[self alloc] init] autorelease];
[path setXLoc:0]; // only if you didn't do this in your init method
[path setYLoc:0]; // only if you didn't do this in your init method
return path;
}
... is the correct (and more elegant) way of doing this, IMHO. Cheers,
(Quick note - there's a missing '[' above...)
Sure enough doing things this way works fine and I don't get an error.
However I'm slightly troubled by not using NSBezierPath's bezierPath
method to create the path object, since that is the documented way to
get an NSBezierPath object. It's possible that bezierPath does
something that the init call does not...
I therefore ended up replacing the MyBez *path line with this:
MyBez *path = (MyBez *)[super bezierPath];
This seems to work just fine, and definitely gives the bezierPath the
chance to initialise correctly.
Thanks again guys,
Steve
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.