When implementing an +initialize or +load method in one of your Objective-C classes, should you always start with this kind of guard?:
@implementation MyClass
+ (void)initialize {
if (self == [MyClass class]) {
...
}
}
...
@end
Seems like code in +load and +initialize usually only wants to be executed once. So this would help avoid dupe execution when subclasses load/initialize.
I guess I'm just wanting some reinforcement from some ObjC wizards that this is necessary/common practice...
What's the common wisdom on this? would you recommend always doing this?
Is your advice the same for both +load and +initialize, or is there a difference in they way they should be handled?
thanks.