• 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: objective-c question/clarification
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: objective-c question/clarification


  • Subject: Re: objective-c question/clarification
  • From: Carlos Weber <email@hidden>
  • Date: Sun, 24 Jun 2001 23:11:34 -1000

On Sunday, June 24, 2001, at 07:40 , email@hidden wrote:

+ (id)sharedInfoWindowController
{
static InfoWindowController *_sharedInfoWindowController = nil;

if (!_sharedInfoWindowController)
_sharedInfoWindowController = [[InfoWindowController allocWithZ$

return _sharedInfoWindowController;
}

The key is the word "static". Its a case of the C language raising its ugly head. This is a quote from K&R:

"... Internal static variables are local to a particular function just as automatic variables are, but unlike automatics, they remain in existence rather than coming and going each time the function is activated. This means that internal static variables provide private, permanent storage within a single function."

I believe this is what is referred to as creating a "singleton"; I've seen this idiom a lot, and it seems to be a way of getting around the fact that Objective-C lacks class variables.


References: 
 >objective-c question/clarification (From: email@hidden)

  • Prev by Date: NSFileManager stripping resource fork
  • Next by Date: Re: objective-c question/clarification
  • Previous by thread: Re: objective-c question/clarification
  • Next by thread: Re: objective-c question/clarification
  • Index(es):
    • Date
    • Thread