方法【load】是否需要调用【super load】

Does method [load] need to call [super load]

我知道很多方法需要调用它的超级class方法,有些方法不需要,

我正在寻找有关方法 swizzling.It 在加载方法中初始化的事情,而在教程中没有 [super load]

我想知道是不是错了还是根本不需要打电话[super load]

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [self class];

        // When swizzling a class method, use the following:
        // Class class = object_getClass((id)self);

        SEL originalSelector = @selector(pushViewController:animated:);
        SEL swizzledSelector = @selector(flbs_pushViewController:animated:);

        Method originalMethod = class_getInstanceMethod(class, originalSelector);
        Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);

        BOOL didAddMethod =
        class_addMethod(class,
                        originalSelector,
                        method_getImplementation(swizzledMethod),
                        method_getTypeEncoding(swizzledMethod));

        if (didAddMethod) {
            class_replaceMethod(class,
                                swizzledSelector,
                                method_getImplementation(originalMethod),
                                method_getTypeEncoding(originalMethod));
        } else {
            method_exchangeImplementations(originalMethod, swizzledMethod);
        }
    });
}

#pragma mark - Method Swizzling

- (void)flbs_pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self flbs_pushViewController:viewController animated:animated];
    });
    NSLog(@"flbs_pushViewController");
}

顺便说一句,此方法用于修复导航损坏。

我偶尔会重现这个问题,我调试了它,我认为是关于 thread.So 我做这个 swizzling 是为了在系统方法中添加一些东西。

如果你能告诉我有关导航损坏问题或此方法调配的问题,我也非常感谢。

来自NSObject documentation (重点添加):

A class’s +load method is called after all of its superclasses’ +load methods.

这意味着您不必从代码中调用 [super load]。 来自所有超类的 load 方法已被调用 在 Objective-C 运行时 before 子类中的方法被调用。