Re: Is Apple's singleton sample code correct?
Re: Is Apple's singleton sample code correct?
- Subject: Re: Is Apple's singleton sample code correct?
- From: Scott Anguish <email@hidden>
- Date: Wed, 30 Nov 2005 03:18:21 -0500
On Nov 30, 2005, at 12:59 AM, Jeff Laing wrote:
myColor = [[NSColor whiteColor] retain];
Hmmm, I had not considered that that would be returning a singleton
at all.
Singleton implies a single instance for the entire class, and this
doesn't return the same object if you call, for example redColor.
These are convenince methods for creating colors. it's subtle, but I
believe it'd be more accurate to say that it returns a shared
immutable object that represents white, rather than a singleton for
NSColor. you'll get a different object for redColor, but again,
likely the same object again if you ask for it again (assumptions
being made on my part here about how this particular aspect works,
I've not checked)
there are other kit cases where shared immutable objects are
returned that you don't necessarily know about. bottom line is, if
you want to ensure that you have a valid reference to it, retain it.
no exceptions (well, weak references I suppose)
_______________________________________________
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