Re: convenience methods
Re: convenience methods
- Subject: Re: convenience methods
- From: "John C. Randolph" <email@hidden>
- Date: Mon, 4 Apr 2005 15:39:15 -0700
On Apr 3, 2005, at 6:11 PM, Julien Palmas wrote:
I've been wondering how to write a convenience class methods.
I've got an implementation that works, but wanted to know if it was
the right way to do it ...
what about this to add a new color to the NSColor class ?
+ (NSColor *)lightRedColor {
return [[NSColor colorWithCalibratedHue:0.0 saturation:0.1
brightness:1.0 alpha:1.0] autorelease];
}
is that ok ?\
Two suggestions...
First, this code will over-release the color.
+colorWithCalibratedHue:saturation:brightness:alpha: returns an
autoreleased NSColor.
Secondly, if you expect this method to be called many times (like,
every time some view gets redrawn), you might want to create a shared
instance, e.g:
+ (NSColor *)lightRedColor {
static NSColor *lightRed
if (!lightRed)
lightRed = [[NSColor colorWithCalibratedHue:0.0 saturation:
0.1 brightness:1.0 alpha:1.0] retain];
return lightRed;
}
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden