• 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: convenience methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >convenience methods (From: Julien Palmas <email@hidden>)

  • Prev by Date: Comments in CF Property Lists ?
  • Next by Date: Changing toolbar after window resizing does not relayout the tools on the toolbar
  • Previous by thread: Re: convenience methods
  • Next by thread: Unable to view Drawer
  • Index(es):
    • Date
    • Thread