Skip to content

Instantly share code, notes, and snippets.

@eXhausted
Last active February 20, 2019 13:17
Show Gist options
  • Save eXhausted/d0fa448bbfcd1e5166f38d314f4477c8 to your computer and use it in GitHub Desktop.
Save eXhausted/d0fa448bbfcd1e5166f38d314f4477c8 to your computer and use it in GitHub Desktop.
put a caller of `-[UIView addSubview:]` to `-[UIView accessibilityIdentifier]`
#ifdef DEBUG
#import <objc/runtime.h>
@interface UIView(swiz)
- (void)debug_addSubview:(UIView *)view;
@end
@implementation UIView(swiz)
+ (void)load {
Method original, swizzled;
original = class_getInstanceMethod(self, @selector(addSubview:));
swizzled = class_getInstanceMethod(self, @selector(debug_addSubview:));
method_exchangeImplementations(original, swizzled);
}
- (void)debug_addSubview:(UIView *)view {
view.accessibilityIdentifier = [NSThread callStackSymbols][1];
[self debug_addSubview:view];
}
@end
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment