Objective-c class initializer executes multiple times
        Posted  
        
            by 
                apisip
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by apisip
        
        
        
        Published on 2012-11-22T22:56:36Z
        Indexed on 
            2012/11/22
            22:59 UTC
        
        
        Read the original article
        Hit count: 306
        
Unless I misunderstood it, this LINK from Apple's documentation clearly states that the class initializer, "+ (void)initialize)", only executes once per class.
Here is the excerpt:
Special Considerations
initialize it is invoked only once per class. If you want to perform independent initialization for the class and for categories of the class, you should implement load methods.
However, I'm getting a weird behavior on my project and the initializer is being executed twice. So I have to check if _classContext is null. I only got one class that has this method. What are the possible reasons why this is happening?
I'm using XCode 4.5.2 and OS X 10.8.2. I got multiple iOS simulators, iPhone 5.1 and 6.0.
+ (void) initialize
{
    num++;
    NSLog([NSString stringWithFormat:@"Times: %i", num]);
    if(_classContext == nil)
        _classContext = [[myClass alloc] init];
} 
© Stack Overflow or respective owner