• 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: Subclassing an object's creation method (NSBezierPath's +bezierPath)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subclassing an object's creation method (NSBezierPath's +bezierPath)


  • Subject: Re: Subclassing an object's creation method (NSBezierPath's +bezierPath)
  • From: Prachi Gauriar <email@hidden>
  • Date: Mon, 31 May 2004 17:22:38 -0500

On Monday, May 31, 2004, at 04:13PM, Steve Sims <email@hidden> wrote:

>On 28 May 2004, at 04:47, Peter Maurer wrote:
>>> + (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];

According to the documentation, you can use init to create a new empty NSBezierPath, so I wouldn't worry:

> You can create an instance of NSBezierPath using the Java constructor or
> any of the class methods bezierPath, bezierPathWithRect:, or
> bezierPathWithOvalInRect:. bezierPath initializes a new bezier-path object
> with an empty path, bezierPathWithRect: creates a path with the specified
> rectangle, and bezierPathWithOvalInRect: creates an oval path inscribed
> within a specified rectangle. In Objective-C, you can also allocate memory
> for a new instance of NSBezierPath and use the default initializer, init, to
> initialize it to an empty path.

I would use the init method, since it probably initializes your xLoc and yLoc to 0.

Moral of the story: just because class documentation doesn't list init doesn't mean you shouldn't use it.

-Prachi
_______________________________________________
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.


  • Prev by Date: Re: Subclass NSApplication in Carbon App?
  • Next by Date: some NSThread questions
  • Previous by thread: Re: Subclassing an object's creation method (NSBezierPath's +bezierPath)
  • Next by thread: symbolic nil
  • Index(es):
    • Date
    • Thread