- #1
aychamo
- 375
- 0
Hello everyone;
I've been reading a document over on Apple's Developer website, called "The Object-C Language."
I'm reading about classes, and there is a part called "Initializing a Class Object" and it gives an example of how to implement an initialize method for a class:
So I assume at runtime you would send [myClass initialize]. What I don't understand, is in that method you declare the static variable initialized to = NO. If the initialize method got called again, wouldn't it set the initialized variable again to NO, and then rerun the initialization?
So my question is, what is the point of declaring the initialized = NO, and then checking if it's not initialaized? Would the initialize method be the only method able to access that initialized variable?
Sorry if this is a really basic question.. I'm trying to learn some basics of object oriented programming and objective-C from the docs.
Thank you
Aychamo
I've been reading a document over on Apple's Developer website, called "The Object-C Language."
I'm reading about classes, and there is a part called "Initializing a Class Object" and it gives an example of how to implement an initialize method for a class:
PHP:
+ (void) initialize
{
static BOOL initialized = NO;
if (!initialized) {
// Perform initialization here
initialized = YES;
}
}
So I assume at runtime you would send [myClass initialize]. What I don't understand, is in that method you declare the static variable initialized to = NO. If the initialize method got called again, wouldn't it set the initialized variable again to NO, and then rerun the initialization?
So my question is, what is the point of declaring the initialized = NO, and then checking if it's not initialaized? Would the initialize method be the only method able to access that initialized variable?
Sorry if this is a really basic question.. I'm trying to learn some basics of object oriented programming and objective-C from the docs.
Thank you
Aychamo