Is the method [load] [super load] required

I know that many methods require calling a superclass method, and some methods are not needed,

I am looking for sth about the swizzling.It method is initialized in the load method, but in the tutorial there is no [super load] .

I am wondering if this is incorrect or just does not need to be called [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"); } 

By the way, this method is used to correct navigation distortion.

Sometimes I had a problem, and I debugged it, I think it concerns the flow. Therefore, I am doing this swizzling to add sth to the system method.

If you can say that there is a problem with navigational corruption or this swizzling method, I also really appreciate it.

+5
source share
1 answer

From the NSObject documentation (highlighted by me):

The class +load method is called after all its superclasses +load .

This means that you do not need to call [super load] from your code. The load method from all superclasses has already been called using the Objective-C runtime before calling the method in your subclass.

+6
source

Source: https://habr.com/ru/post/1239554/


All Articles