• 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: Is Apple's singleton sample code correct?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: Is Apple's singleton sample code correct?
      • From: glenn andreas <email@hidden>
References: 
 >RE: Is Apple's singleton sample code correct? (From: Jeff Laing <email@hidden>)

  • Prev by Date: Re: [More Questions ]Has anyone any experience with NSTableView and NSArrayController ?
  • Next by Date: Re: NSArrayController usage
  • Previous by thread: RE: Is Apple's singleton sample code correct?
  • Next by thread: Re: Is Apple's singleton sample code correct?
  • Index(es):
    • Date
    • Thread