Last active
February 20, 2019 13:17
-
-
Save eXhausted/d0fa448bbfcd1e5166f38d314f4477c8 to your computer and use it in GitHub Desktop.
put a caller of `-[UIView addSubview:]` to `-[UIView accessibilityIdentifier]`
This file contains 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
#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