2010-11-26 37 views

回答

13

使用你的类的+initialize方法:(更新添加if (self == [MyClass class])条件,如意见提出)

@implementation MyClass 

static NSUInteger counter; 

+(void)initialize { 
    if (self == [MyClass class]) { 
     counter = 0; 
    } 
} 

@end 

+2

另外,你可能想确保了`initialize`不会运行两次如果课程是分类的? – zoul 2010-11-26 08:26:36