초기화 메소드에서 [self class] == [levelAppDelegate 클래스]를 확인 해야하는 이유는 무엇입니까?
-
06-07-2019 - |
문제
Apple의 Bubblelevel 예제의 AppDelegate에서 그들은 다음과 같은 일을합니다.
+ (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];
}
}
왜 [self class] == [levelAppDelegate 클래스]를하는 이유는 무엇입니까?
해결책
이 테스트는 서브 클래스가로드 될 때 초기화가 호출되면 초기화 코드가 영향을 미치지 않도록합니다.
제휴하지 않습니다 StackOverflow