Re: objective-c question/clarification
Re: objective-c question/clarification
- Subject: Re: objective-c question/clarification
- From: Raphael Sebbe <email@hidden>
- Date: Mon, 25 Jun 2001 10:46:58 +0200
Just like in C, static variables are global variables whose scope is
limited to the function in which they are defined.
The =nil statement is only for initialization (done once, and not each
time you call the function), the actual value is kept between calls.
You should find documentation about this in any C book.
Raphael
On Monday, June 25, 2001, at 07:40 AM, email@hidden wrote:
I was working through the rest of ToDo example from the O'Reilly Cocoa
and the code snippet below bothered me as there seems to be a hole in
my obj-c knowledge. The first line in the code declares a static local
variable "InfoWindowController" which it then proceeds to set to nil.
The subsequent "if" statement checks to see if the
"InfoWindowController" is pointed at anything. Wouldn't
"InfoWindowController" always be nil thus allowing for the creation of
numerous "info windows" (which I know does not happen). I'm just
curious as to the mechanism behind this code, why it works.
From InfoWindowController.m
+ (id)sharedInfoWindowController
{
static InfoWindowController *_sharedInfoWindowController = nil;
if (!_sharedInfoWindowController)
_sharedInfoWindowController = [[InfoWindowController
allocWithZ$
return _sharedInfoWindowController;
}
Thanks,
Ryan Cuprak
-----------------------------------------------------------------------------------------
Ryan Cuprak <email@hidden> www.cuprak.net
(860)-742-5561
46 Prospect St.
Coventry, CT 06238
-----------------------------------------------------------------------------------------
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev