Skip to content

Instantly share code, notes, and snippets.

@adamweeks
Last active January 9, 2017 06:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adamweeks/5701041 to your computer and use it in GitHub Desktop.
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.
#import "UIViewController+Logging.h"
#import <UIKit/UIKit.h>
@interface UIViewController (Logging)
@end
#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