The Objective-C version of onevcat's DebuggableContext
-
Implement
DebuggableContext
protocol@interface UIViewController (Debuggable) <DebuggableContext> #if DEBUG - (nonnull NSArray<DebuggableContextItem *> *)debuggableMenus { return @[ [[DebuggableContextItem alloc] initWithName:@"Debuggable" action:^{ NSLog(@"Debuggable"); }], [[DebuggableContextItem alloc] initWithName:@"Debuggable" action:^{ NSLog(@"Debuggable"); }] ]; } #endif
-
Register at proper time.
- (void)viewDidLoad { [super viewDidLoad]; REGISTER_DEBUG(self); }
-
Replace the main
UIWindow
toShakeWindow
atAppDelegate
.- (UIWindow *)window { #if DEBUG return [self shakeWindow]; #else if (!_window) { _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; } return _window; #endif } - (ShakeWindow *)shakeWindow { if (!_shakeWindow) { _shakeWindow = [[ShakeWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; _shakeWindow.backgroundColor = [UIColor redColor]; } return _shakeWindow; }
-
Trigger shake gesture at runtime (
Cmd+Ctrl+Z
for simulator)
If too much displayed DebuggableContextItem
, and you only need to show a bit of them, implement filterContext:
to filter it.
- (BOOL)filterContext:(id<DebuggableContext>)target {
return [NSStringFromClass([target class]) isEqualTo:NSStringFromClass([self class])]
}