Last active
January 9, 2017 06:05
-
-
Save adamweeks/5701041 to your computer and use it in GitHub Desktop.
WTVC!?! What-the-View-Controller?!?! This UIViewController+Logging class category utilizes method swizzling to help you log which view is currently being displayed. This comes in handy when investigating a very large project with lots of view controllers that are hard to track down. Simply import this in your App Delegate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "UIViewController+Logging.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface UIViewController (Logging) | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "UIViewController+Logging.h" | |
#import <objc/runtime.h> | |
@implementation UIViewController (Logging) | |
-(void)swizzled_viewDidAppear:(BOOL)animated | |
{ | |
NSLog(@"Current View Did Appear Class: %@", NSStringFromClass(self.class)); | |
[self swizzled_viewDidAppear:animated]; | |
} | |
-(void)swizzled_viewDidLoad | |
{ | |
NSLog(@"Current View Loaded Class: %@", NSStringFromClass(self.class)); | |
[self swizzled_viewDidLoad]; | |
} | |
+ (void)load | |
{ | |
Method original, swizzled; | |
original = class_getInstanceMethod(self, @selector(viewDidAppear:)); | |
swizzled = class_getInstanceMethod(self, @selector(swizzled_viewDidAppear:)); | |
method_exchangeImplementations(original, swizzled); | |
original = class_getInstanceMethod(self, @selector(viewDidLoad)); | |
swizzled = class_getInstanceMethod(self, @selector(swizzled_viewDidLoad)); | |
method_exchangeImplementations(original, swizzled); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment