Reputation: 40339
In the AppDelegate of the BubbleLevel example from Apple they do something like this:
+ (void)initialize {
if ([self class] == [LevelAppDelegate class]) {
// Register a default value for the instrument calibration.
// This will be used if the user hasn't calibrated the instrument.
NSNumber *defaultCalibrationOffset = [NSNumber numberWithFloat:0.0];
NSDictionary *resourceDict = [NSDictionary dictionaryWithObject:defaultCalibrationOffset forKey:BubbleLevelCalibrationOffsetKey];
[[NSUserDefaults standardUserDefaults] registerDefaults:resourceDict];
}
}
Why do they do that [self class] == [LevelAppDelegate class] ?
Upvotes: 1
Views: 186
Reputation: 6263
This test ensures that the initialization code has no effect if initialize is invoked when a subclass is loaded.
Upvotes: 3