diff --git a/TBUIAutoTest/TBUIAutoTest.m b/TBUIAutoTest/TBUIAutoTest.m index 5285641..c6c8307 100644 --- a/TBUIAutoTest/TBUIAutoTest.m +++ b/TBUIAutoTest/TBUIAutoTest.m @@ -44,19 +44,17 @@ @implementation NSObject (TBUIAutoTest) + (void)swizzleSelector:(SEL)originalSelector withAnotherSelector:(SEL)swizzledSelector { - Class aClass = [self class]; - - Method originalMethod = class_getInstanceMethod(aClass, originalSelector); - Method swizzledMethod = class_getInstanceMethod(aClass, swizzledSelector); + Method originalMethod = class_getInstanceMethod(self, originalSelector); + Method swizzledMethod = class_getInstanceMethod(self, swizzledSelector); BOOL didAddMethod = - class_addMethod(aClass, + class_addMethod(self, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); if (didAddMethod) { - class_replaceMethod(aClass, + class_replaceMethod(self, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); diff --git a/TBUIAutoTest/UIImage+TBUIAutoTest.m b/TBUIAutoTest/UIImage+TBUIAutoTest.m index 8e13d8f..8400d0e 100644 --- a/TBUIAutoTest/UIImage+TBUIAutoTest.m +++ b/TBUIAutoTest/UIImage+TBUIAutoTest.m @@ -8,6 +8,7 @@ #import "UIImage+TBUIAutoTest.h" #import "TBUIAutoTest.h" +#import @implementation UIImage (TBUIAutoTest) + (void)load @@ -28,8 +29,9 @@ + (void)load { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - [self swizzleSelector:@selector(imageNamed:) withAnotherSelector:@selector(tb_imageNamed:)]; - [self swizzleSelector:@selector(imageWithContentsOfFile:) withAnotherSelector:@selector(tb_imageWithContentsOfFile:)]; + [object_getClass(self) swizzleSelector:@selector(imageNamed:) withAnotherSelector:@selector(tb_imageNamed:)]; + [object_getClass(self) swizzleSelector:@selector(imageWithContentsOfFile:) withAnotherSelector:@selector(tb_imageWithContentsOfFile:)]; + [self swizzleSelector:@selector(accessibilityIdentifier) withAnotherSelector:@selector(tb_accessibilityIdentifier)]; }); } @@ -57,4 +59,16 @@ + (UIImage *)tb_imageWithContentsOfFile:(NSString *)path return image; } +- (id)assetName {return nil;} + +- (NSString *)tb_accessibilityIdentifier { + NSString *tb_accessibilityIdentifier = [self tb_accessibilityIdentifier]; + if (tb_accessibilityIdentifier.length == 0 && [self respondsToSelector:@selector(imageAsset)]) { + tb_accessibilityIdentifier = [(id)self.imageAsset assetName]; + self.accessibilityIdentifier = tb_accessibilityIdentifier; + } + + return tb_accessibilityIdentifier; +} + @end diff --git a/TBUIAutoTestDemo/TBUIAutoTestDemo/Assets.xcassets/AppIcon.appiconset/Contents.json b/TBUIAutoTestDemo/TBUIAutoTestDemo/Assets.xcassets/AppIcon.appiconset/Contents.json index 36d2c80..d8db8d6 100644 --- a/TBUIAutoTestDemo/TBUIAutoTestDemo/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/TBUIAutoTestDemo/TBUIAutoTestDemo/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -30,6 +40,16 @@ "size" : "60x60", "scale" : "3x" }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, { "idiom" : "ipad", "size" : "29x29", @@ -59,6 +79,16 @@ "idiom" : "ipad", "size" : "76x76", "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : {