Logging the class name of all UIViewControllers in a project

后端 未结 7 812
一生所求
一生所求 2020-12-28 22:51

We have received a HUGE project from outsourcing that we are trying to \"repair\". There are hundreds of view controllers within the project. Our goal is to

7条回答
  •  余生分开走
    2020-12-28 23:29

    The answer is to swizzle the methods! Here is what we came up with:

    #import "UIViewController+Logging.h"
    #import 
    
    @implementation UIViewController (Logging)
    
    -(void)swizzled_viewDidAppear:(BOOL)animated
    {
        NSLog(@"Current View Class: %@", NSStringFromClass(self.class));
        [self swizzled_viewDidAppear:animated];
    }
    
    + (void)load
    {
        Method original, swizzled;
    
        original = class_getInstanceMethod(self, @selector(viewDidAppear:));
        swizzled = class_getInstanceMethod(self, @selector(swizzled_viewDidAppear:));
    
        method_exchangeImplementations(original, swizzled);
    
    }
    @end
    

提交回复
热议问题